First, cocos2dhtml5 uses javascript programming, which is case sensitive.
1. Create a cocos2dhtml5 project.
Directly copy the built-in helloworld of the engine and change the folder name.
2. Add a js File
When adding a js file to your project, you need to add your file name to the appFiles in cocos2d. js:
appFiles:[ 'src/resource.js', 'src/Load.js', 'src/DragonLayer.js'//add your own files in order here ]
There is also the final addition of build. xml
3. Resource files
The resource files of cocos2dhtml are stored in the res directory. all the resources we need to use must be written in the resource. js file under the src directory:
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, commonly used in cocos2d-x operations in js writing:
CCLOG (cc. log), ccc3 (cc.3b), ccc4 (cc. c4b), ccc4f (cc. c4f), ccp (cc. p), CCSize (cc. size), CCRect (cc. rect)
6. Array
Javascript is a weak type language, and no CCArray or CCDictionary is available here, because any Javascript Object has the basic features 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 cc. dump to output the description of the object.
8, cocos2d-x and cocos2dhtml5 instance code is basically the same, you can view the sample in samples/tests you want, here we can find some cocos2dhtml5 differences, it can basically meet 80% of our needs.