The difference from COCOS2DX to COCOS2DHTML5

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.