Game Development Reference
In-Depth Information
Ending and Replaying the Game
The final game logic is to end the game and restart it. The game over state will simply add a Play Again button, which
is done in the function gameOver , shown in Listing 7-29.
Listing 7-29. The gameOver Function Creates a Play Again Button and Puts It in Place of the Fakezee
Category Button
function gameOver() {
var playAgainBtn = new createjs.Sprite(spritesheet, 'playAgain');
var fakezeeBtn = scoreCard.getChildByName('fakezee');
playAgainBtn.regX = fakezeeBtn.regX;
playAgainBtn.regY = fakezeeBtn.regY;
playAgainBtn.x = fakezeeBtn.x;
playAgainBtn.y = fakezeeBtn.y;
playAgainBtn.on('click', replayGame);
scoreCard.addChild(playAgainBtn);
scoreCard.removeChild(fakezeeBtn);
scoreCard.mouseEnabled = true;
}
The Play Again button is a sprite and will completely replace the Fakezee button (see Figure 7-15 ).
Figure 7-15. The game Fakezee when all scores are counted and the game is complete
Its click handler is the function replayGame , shown in Listing 7-30.
 
Search WWH ::




Custom Search