Creating the Update Loop

The Brain Eater game uses two loops during game play. The game executes an update loop to update the positions of the player and the zombies. The game also executes a render loop to render the game.

The update loop executes every 250 milliseconds. The executeUpdateLoop() method is triggered with the following call to the window.setInterval() method when you start a game:

this._updateLoopId = window.setInterval(this.executeUpdateLoop.bind(this), UPDATE_LOOP_RATE);

Note

The bind() method called on the executeUpdateLoop() method is used to bind the current instance of the Game object to the executeUpdateLoop() method when the executeUpdateLoop() method is called. In other words, it ensures ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.