O'Reilly logo

Multiplayer Game Development with HTML5 by Rodrigo Silveira

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

Understanding the game loop

The next set of changes that we'll need to make on the original game code is in the game class. As you'll remember, this class defines a basic game life cycle, exposing the functions update and render, which get implemented by whoever uses it.

Since the core of the game loop defined in this class (found in Game.prototype.loop) uses window.requestAnimationFrame, we'll need to get rid of that call since it will not be available in Node.js (or in any other environment outside the browser).

One technique that is commonly used to allow us the flexibility to write a single module that is used in both the browser and the server is to wrap the browser- and server-specific functions in a custom module.

Using Browserify, we can ...

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