HTML and CSS Reference
In-Depth Information
Figure 24-19. Tower Defence Game over scenes
Now create a GameOver.js file and add it to appFiles array. The game over scene contains only one
GameOverLayer . The GameOverLayer can be created as shown in Listing 24-20.
Listing 24-20. Defining the GameOverLayer in GameOver.js
var GameOverLayer = cc. Layer.extend ( {
init : function ( win ) {
this._super ( ) ;
var backgroudImage = null ;
var titleImage = null ;
var winSize = cc.Director.getInstance ( ).getWinSize ( ) ;
if ( win ) {
// Congratulations, you win
backgroudImage = s_StartBG ;
titleImage = s_Win ;
} else {
// Oh, no, you lose
backgroudImage = s_LoseBG ;
titleImage = s_Lose ;
}
// init background
var background = cc.Sprite.create ( backgroudImage ) ;
background.setPosition ( winSize. width / 2, winSize.height / 2 ) ;
this.addChild ( background , 0 ) ;
// init title
var title = cc. Sprite.create ( titleImage ) ;
title.setPosition ( winSize. width / 2, winSize.height * 3 / 4 ) ;
cc.log ( winSize.width / 2 ) ;
cc.log ( winSize.height / 2 ) ;
this.addChild ( title , 1 ) ;
// add the score on the screen
score = cc.LabelTTF . create ( "Score:" + HD. SCORE , "Arial" , 28 ) ;
score.setAnchorPoint ( cc. p( 0.5 , 0.5 ) ) ;
score.setHorizontalAlignment ( cc. TEXT_ALIGNMENT_CENTER ) ;
Search WWH ::




Custom Search