Book Image

jQuery Game Development Essentials

By : Selim Arsever
Book Image

jQuery Game Development Essentials

By: Selim Arsever

Overview of this book

jQuery is a leading multi-browser JavaScript library that developers across the world utilize on a daily basis to help simplify client-side scripting. Using the friendly and powerful jQuery to create games based on DOM manipulations and CSS transforms allows you to target a vast array of browsers and devices without having to worry about individual peculiarities."jQuery Game Development Essentials" will teach you how to use the environment, language, and framework that you're familiar with in an entirely new way so that you can create beautiful and addictive games. With concrete examples and detailed technical explanations you will learn how to apply game development techniques in a highly practical context.This essential reference explains classic game development techniques like sprite animations, tile-maps, collision detection, and parallax scrolling in a context specific to jQuery. In addition, there is coverage of advanced topics specific to creating games with the popular JavaScript library, such as integration with social networks alongside multiplayer and mobile support. jQuery Game Development Essentials will take you on a journey that will utilize your existing skills as a web developer so that you can create fantastic, addictive games that run right in the browser.
Table of Contents (17 chapters)
jQuery Game Development Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Offline divs


As explained at the end of the previous chapter, avoiding reflow is a good way to speed things up. It's not always easy to completely avoid querying the state of the DOM during your manipulations. And even if you are very careful, as a framework developer, you are never sure what the user of your framework will do. However, there is a way to reduce the negative effect of a reflow; detach the piece of DOM you are working on, modify it, and then attach it back to the document.

Let's say you have a node with the ID box and want to manipulate its child elements in a complex manner. The following code shows you how to detach it:

// detach box
var box = $("#box").detach();

var aSubElement = box.find("#aSubElement")
// and so on

// attach it back
box.appendTo(boxParent);

This requires a small modification of our framework's API; until now, we used a string to identify sprites. This has the side effect of requiring the sprite to be part of the document. For example, if you call gf.x...