Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By : Kerri Shotts
Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By: Kerri Shotts

Overview of this book

<p>PhoneGap allows you to use your existing knowledge of HTML, CSS, and JavaScript to create useful and exciting mobile applications.<br /><br />This book will present you with 12 exciting projects that will introduce you to the dynamic world of app development in PhoneGap. Starting with their design and following through to their completion, you will develop real-world mobile applications. Each app uses a combination of core PhoneGap technologies, plugins, and various frameworks covering the necessary concepts you can use to create many more great apps for mobile devices.</p>
Table of Contents (21 chapters)
PhoneGap 3.x Mobile Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Performing updates


Of course, drawing the same frame over and over won't do any good. We need to update the game too. This includes responding to user input, checking for collisions, and moving us along the cave.

Getting on with it

We'll be doing all our updating in… guess what—doUpdate in www/js/app/views/gameView.js.

If you recall from the last task, the only incoming parameter is the incoming frame multiplier. We want this to be 1, but it might be 2 if we're getting 30 fps, or 4 if we're getting 15 fps. We'll use the frame multiplier at various points to multiply any updates so that everything moves as if we were getting 60 fps, even when we aren't. Let's use the following code for this purpose:

self._doUpdate = function ( f ) {
var gameOver = false;
var levelOver = false;
var oldShip = {x: self._ship.x,
               y: self._ship.y };

The first step of our update process is to record the current value of the ship. We need this to properly detect collisions later as the position of our ship...