HTML and CSS Reference
In-Depth Information
this.addChild ( score , 100 ) ;
score.setPosition ( winSize. width / 2, winSize.height / 2 + 30 ) ;
... ...
// add start button here
} ) ;
You will notice that setPosition accepts two types of parameters: x and y or cc.p() .
After creating GameOverLayer , connect it to GameOverScene , as shown in Listing 24-21.
Listing 24-21. Connecting the GameOverLayer to GameOverScene in GameOver.js
var GameOverScene = cc.Scene.extend ( {
ctor : function ( win ) {
//cc.log(win)
this._super ( ) ;
var layer = new GameOverLayer ( ) ;
layer.init ( win ) ;
this.addChild ( layer ) ;
}
} ) ;
As the code in Listing 24-21 shows, the GameOverScene will be created with a different background and a different
title according to the win parameter.
Deploying the Game
After finishing the game coding, you can package all of the JavaScript files into a single obfuscated file for security.
Before packaging, you should add all of your JavaScript files to build.xml , which is found in the /root/Cocos2d-
html5-v2.2.2/HalloweenDefence folder.
Open Terminal app. Use the cd command to switch to the directory where build.xml is stored, and execute ant ,
as shown in Listing 24-22. The resulting screen appears in Figure 24-20 .
Listing 24-22. Packaging JavaScript Files
cd ~/work/HalloweenDefence/Cocos2d-html5-v2.2.2/HalloweenDefence
ant
Figure 24-20. Packaging game files
 
Search WWH ::




Custom Search