O'Reilly logo

Beginning Facebook Game Apps Development by Wayne Graham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Coding the Engine

I take an iterative approach to writing this game, adding layers to the game to build and hone it to a working game. With the scaffold out of the way, the first thing I want to do is create some variables that will store the canvas DOM element, as well as create a context for the game. Below the <footer>, add a <script> element with Listing 6–5.

Listing 6–5. Defining the canvas Element

<script> var canvas = document.getElementById('game'); var context = canvas.getContext('2d'); </script>

I am placing the script at the bottom of the page to ensure that all the page content loads before the code for the game loads into the browser’s memory. Next, I want to stub out a gameLoop function that will handle all the drawing on the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required