O'Reilly logo

Building HTML5 Games with ImpactJS by Jesse Freeman

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

Customizing the Main Class

To get started, let’s delete the font code from the draw method, but make sure you leave this.parent(). We can also now delete the font variable from the beginning of the class.

Now with the “It Works!” text removed, the first thing we want our game to do when it starts is load the level we just created. Change the .requires(...) block to load the level:

.requires(
    'impact.game',
    'game.levels.dorm1'
)

Unfortunately, if you refresh your game, nothing is going to display. We will need to tell the game to load our level. Add the following code to your init() method:

init: function() {
    this.loadLevel( LevelDorm1 );
},

Now, refresh your game.

The level loaded when the game is refreshed.

Figure 4-10. The level loaded when the game is refreshed.

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