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

Parallax scrolling


Parallax scrolling is a very neat way of giving a little depth to a 2D game. It uses the principle that the farther away objects are, the slower they seem to move. It's typically what you see when you look through the side window of a moving car.

The first layer in the preceding figure will be the group containing all the sprites and the tile map. The second and third layers will simply be images. We will use the same technique we used in the previous game: we will simply use the background position to generate their movement.

The final code takes place in the main game loop just after we move the group around to keep the player visible on screen:

var margin = 200;
var playerPos = gf.x(player.div);
if(playerPos > 200) {
    gf.x(group, 200 - playerPos);
    $("#backgroundFront").css("background-position",""+(200 * 0.66 - playerPos * 0.66)+"px 0px");
    $("#backgroundBack").css("background-position",""+(200 * 0.33 - playerPos * 0.33)+"px 0px");
}

As you can see, the code...