Game Development Reference
In-Depth Information
setTimeout(function(){
me.dispatchEvent(game.GameStateEvents.GAME_OVER);
},3000)
}
window.game.Game = Game;
}(window));
When the game initializes, a simple setTimeout method is used, which will dispatch the game event to move on
to the game over scene. This is temporary. Meanwhile, there is one more scene container class to set up.
Creating the Game Over Scene
The game over scene is the final screen in the game, and it should appear when the player loses all of their lives. A
Game Over title, which is another sprite from the sprite sheet, will scale up while rotating in a full circle. The score is
also displayed to show the player how well they did in the game. Below that are two buttons that play the game again
or return the player to the main menu. The entire GameOver class is show in Listing 11-14.
Listing 11-14. The GameOver Scene Class, Declared in GameOver.js
(function (window) {
window.game = window.game || {}
function GameOver() {
this.initialize();
}
var p = GameOver.prototype = new createjs.Container();
p.Container_initialize = p.initialize;
p.initialize = function () {
this.Container_initialize();
createjs.Sound.stop();
this.addMessage();
this.addScore();
this.addButton();
}
p.addMessage = function () {
var msg = new createjs.Sprite(spritesheet, 'gameOver');
msg.regX = msg.getBounds().width / 2;
msg.regY = msg.getBounds().height / 2;
msg.x = screen_width / 2;
msg.y = 250;
msg.scaleX = msg.scaleY = 0;
createjs.Tween.get(msg).to({scaleX:1, scaleY:1, rotation:360}, 500);
this.addChild(msg);
}
 
Search WWH ::




Custom Search