HTML and CSS Reference
In-Depth Information
renderMode : 1 , //Choose of RenderMode: 0(default), 1(Canvas only), 2(WebGL only)
tag : 'gameCanvas' , //the dom element to run Cocos2d on
engineDir : '../Cocos2d/' ,
//SingleEngineFile:'../../lib/Cocos2d-html5-v2.2.2.min.js',
appFiles : [
'src/GameLayer.js' ,
'src/GameMaps.js' ,
"src/Monster.js" ,
"src/Tower.js" ,
'src/resource.js',
"src/QuadTree.js",
'src/SystemMenu.js',
"src/GameOver.js"
]
} ;
} ) ( ) ;
When you create your own JavaScript files for the game, remember to add them into the
appFiles
array.
Similarly, you have to define all of your resources in
resources.js
and then preload them (see Listings 24-5A and
24-5B). Remember to add
resources.js
and other new JavaScript files into the appFiles array.
Listing 24-5A.
Adding Background Tile Maps to the Resources Preloading Array in
resources.js
var s_DtMapsTmx = "res/DtMaps.tmx" ;
var s_DtMapsImage = "res/DtMaps.png" ;
var g_resources = [
//image
{ src : s_DtMapsImage } ,
//tmx
{ src : s_DtMapsTmx }
] ;
Listing 24-5B.
applicationDidFinishLaunching
Function Preloads Resources in
main.js
applicationDidFinishLaunching : function ( ) {
//load resources
cc. LoaderScene.preload ( g_resources , function ( ) {
director. replaceScene ( new this.startScene ( ) ) ;
} , this ) ;
return true ;
}
The
g_resouces
will be preloaded when the engine executes the
applicationDidFinishLaunching()
function in
main.js
.
After preloading, the engine will call
this.startScene()
to launch the game.
this.startScene
is an operator
and member of the class
cocos2dApp
. It will set the start scene
SytemMenuScene
to
this.startScene
in the
ctor()
function, which is your game main menu. Next, take a look at launching code on the last line of the
main.js
file.
The game will be launched after executing this code.
var myApp = new cocos2dApp(SystemMenuScene);