Game Development Reference
In-Depth Information
When all files are loaded, the assetsComplete function removes the preloader container, and calls on the
functions to create the sprite sheet and create the start menu (see Listing 9-18).
Listing 9-18. Sprite Sheet Creation and a Simple Start Menu
function createSpriteSheet() {
var assets = game.assets;
spritesheet = new
createjs.SpriteSheet(assets.getAsset(assets.GAME_SPRITES_DATA));
}
function buildStartMenu() {
var button = new ui.SimpleButton('PLAY GAME');
button.regX = button.width / 2;
button.regY = button.height / 2;
button.x = canvas.width / 2;
button.y = canvas.height / 2;
button.on('click', startGame);
stage.addChild(button);
stage.update();
}
The spritesheet object is created and stored away. Notice how the sprite sheet data is utilizing the assets class
to retrieve the preloaded JSON file. Next, in buildStartMenu , a simple button is created that will start the game ticker
by calling the startGame function (see Figure 9-3 ).
Figure 9-3. Start menu using the SimpleButton component
When the play game button is clicked, startGame is called (see Listing 9-19).
 
Search WWH ::




Custom Search