Differences between cocos2dx and cocos2dhtml5

Source: Internet
Author: User

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.


Related Article

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.