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

Drawing on the canvas


Of course, it does no good to generate a level if we don't display it to the player. That's what we'll be doing in this task.

Getting on with it

We've already set our canvas up in a prior section. Now, however, we need to define the code that actually draws a frame. We need this code to be quick; however, we have to do it in 16 milliseconds if we hope to approach 60 fps. The drawing code is in the _doAnim method in www/js/app/views/gameView.js. Let's start with the following code:

if (typeof timestamp == "undefined") { 
  timestamp = (new Date()).getTime(); }
var diff = timestamp - self._startTime;

The very first step is to determine the difference between the current time (or the time passed in to the function) and the time the last frame was rendered. This is critical in order to keep the game speed from lagging when frames are dropped.

var ctx = self._context;

Next, we copy the context to a shorter, local variable, because we're going to be using it a lot to draw lines...