First COCOS2DHTML5 is programmed with JavaScript, which is strictly case-sensitive.
1, New COCOS2DHTML5 project.
Directly copy the engine's own HelloWorld, change the folder name.
2. Add JS file
When you add a new JS file to your project, you need to add your file name to the appfiles inside the cocos2d.js:
appfiles:[ ' src/resource.js ', ' src/load.js ', ' src/dragonlayer.js '//add your own files in order here ]
And the last additions to the build.xml.
<sources dir= "${basedir}" > <file name= "src/resource.js"/> <file name= "Src/dragonlayer.js"/ > <file name= "src/load.js"/> <file name= "main.js"/> </sources>
3. Resource Files
cocos2dhtml resource files are placed in the Res directory, we need to use the resources required in the SRC directory in the resource.js file to write it again:
var S_helloworld = "Res/helloworld.png"; var s_bg = "Res/bg.png"; var S_json = "Res/xxx.json"; var s_plist = "Res/xxx.plist"; var S_exportjson = "Res/xxx. Exportjson "; var s_music =" Res/xxx.mp3 "; var g_resources = [ s_helloworld, s_bg, S_json, s_plist, S_exportjson, S_music,];
4, cocos2d-x commonly used in JS in the wording of the operation:
Cclog (Cc.log), CCC3 (cc.3b), CCC4 (cc.c4b), ccc4f (cc.c4f), CCP (CC.P), Ccsize (cc.size), Ccrect (Cc.rect)
6. Arrays
JavaScript is a weakly typed language, and there is no ccarray,ccdictionary here, because any JavaScript object has the basic properties of arrays and dictionaries.
Create an array:
var pointarray = new Array (72); var r = 20; for (var i= 0; i<72; i++) { Pointarray[i] = CC.P (This.guidetou.x+r*math.cos (I*MATH.PI/36), this.guidetou.y+r* Math.sin (I*MATH.PI/36)); }
7, you can use the Cc.dump output object description information.
8, Cocos2d-x and COCOS2DHTML5 example code is basically the same, you can see the samples/tests inside the sample you want, here we can find some cocos2dhtml5 differences, basically can meet our 80% demand.