HTML and CSS Reference
In-Depth Information
s_StartSelected ,
function ( ) {
// when clicked, launch the game play scene.
cc.Director.getInstance( ).replaceScene( new GameScene ( ) ) ;
} , this ) ;
StartItem.setAnchorPoint ( cc.p( 0.5, 0.5 ) ) ;
var menu = cc.Menu.create ( StartItem ) ; // create the menu with the start menu item
menu.setPosition( cc.p( 0 , 0 ) ) ;
this.addChild ( menu , 1 ) ;
StartItem.setPosition ( winSize.width / 2, winSize.height / 2 - 20 ) ;
}
} ) ;
Now the game main menu layer is ready, and you can connect it to the main menu, as shown in Listing 24-7.
Listing 24-7. Connecting the SystemMenuLayer to SytemMenuScene in SystemMenu.js
var SystemMenuScene = cc.Scene.extend ( {
onEnter : function ( ) {
this._super ( ) ;
var layer = new SystemMenuLayer ( ) ;
layer.init ( ) ;
this.addChild ( layer ) ;
}
} ) ;
Once the scene is created, an onEnter() function should be defined. It defines the SystemMenuLayer as its child.
You can also define SystemMenuLayer in the ctor() function instead of the onEnter() function, because the ctor()
function will be called automatically when the scene object is created.
Make sure that you add all of the resources in resources.js before using it, as you did in Listing 24-5A. The main
menu will display on your screen.
Creating the Game Layer, Toolbar Layer, and Game Map Layer
Now it is time to create the game play scene. The first thing to do when creating a game play scene is to build a game
layer. It contains all of the other layers, such as the Game Map layer, Tower layer, Monster layer, Bullet layer, and
Toolbar layer.
You should create a GameLayer.js file and add it to appFiles array. The code to do this is provided in Listing 24-8.
Listing 24-8. Defining the Game Layer and Add Sub-layer to it ( GameLayer.js)
// Extern GameLayer from standard cc.Layer.
var GameLayer = cc.Layer.extend({
_maps:null,
_winSize:null,
init : function(){
this._super();
this._winSize = cc.Director.getInstance().getWinSize();
// init game maps
this.initMaps(); //Add and init your game map.
 
Search WWH ::




Custom Search