First, COCOS2DHTML5 uses JavaScript programming to strictly differentiate between uppercase and lowercase.
1, New COCOS2DHTML5 project.
Direct replication engine comes with HelloWorld. You can change the name of the catalogue.
2. Add JS file
When you add a new JS file to your project, you will 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 addition of 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 folder, we need to use the resources required in the SRC folder in the Resource.js file to write 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 often use the operation in the JS wording:
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 arbitrary JavaScript objects have 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, can use the Cc.dump output object descriptive narrative information.
8, Cocos2d-x and COCOS2DHTML5 example code is basically the same, you can see in samples/tests inside the demo sample you want, here we can find some cocos2dhtml5 differences, basically can meet our 80% demand.
The difference from COCOS2DX to COCOS2DHTML5