Some key points of Javascript development in Cocos2d-x

Source: Internet
Author: User
Document directory
  • 2. When is CCB loaded?
  • 4. the correspondence of several commonly used cocos2d-x units in C ++ and JS (jsb_coco2d.js)
  • 5. Type
  • 6. Dynamic
1. MVC mode in cocosbuilder and JavaScript

VaR scene = cc. builderreader. loadasscene ("checkupdatelayer ");

VaR layer = cc. builderreader. Load ("checkupdatelayer ");

These two lines of code are loaded into scene and layer respectively.

In general, we will create a checkupdatelayer. JS. Note that the "checkupdaelayer" entered in "JS controller" is not a layer, but a real controller, because cocosbuilder adopts the MVC mode.

For example, if you add a method in checkupdatelayer. JS, as follows:

Checkupdatelayer. Prototype. Foo = function (){

Cc. Log ("this is afunction ");

}

This Foo method is actually a controller method, not a layer or scene method.

2. When is CCB loaded?

Checkupdatelayer. Prototype. ondidloadfromccb =
Function (){

Cc. Log ("checkupdatelayerinit ");

VaR L = cc. layercolor. Create (CC. C3b (33,233, 0 ),
200,200 );

This. rootnode. addchild (L );

}

 

Open jsb_cocosbuilder.js and find the CC. builderreader. Load Method. You will see the answer to your questions.

 

3. generated/cocos2dxapi. js all error.

The classes in are all prefixed with CC, such as CC. ccnode, CC. cclayer, CC. ccsprite, but actually in JS, there is no prefix, such as CC. node, CC. layer, CC. sprite, etc...

 

4. the correspondence of several commonly used cocos2d-x units in C ++ and JS (jsb_coco2d.js)

C ++

Javascript

Cclog

Cc. Log

Ccc3

Cc. C3b

Ccc4

Cc. C4B

Ccc4f

Cc. c4f

CCP

Cc. p

Ccsize (W, H)

Cc. Size

Ccrect (X, Y, W, H)

Cc. rect

 

 

5. Type

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.

 

6. Dynamic

When writing C ++, I envy the dynamic characteristics of objective-C. For example, nslog (@ "% @", OBJ) can output the description of the object. but in Javascript, everything is cloudification and CC. dump can meet your needs.

 

7. Look at the cocos2d-2.1beta3-x-2.1.1/samples/JavaScript in a few demos, will solve your 90% questions.

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.