Some key points of Javascript development in Cocos2d-x

Source: Internet
Author: User

1. the MVC pattern var scene = cc In CocosBuilder and Javascript. builderReader. loadAsScene ("CheckUpdateLayer"); var layer = cc. builderReader. load ("CheckUpdateLayer"); these two lines of code are loaded into scene and layer. 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, in CheckUpdateLayer. A method is added in js as follows: CheckUpdateLayer. prototype. foo = function () {cc. log ("this I S afunction ");} the foo method is actually a Controller method, not a Layer or Scene method. 2. When is the CCB Loading completed? 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 cc. builderReader. load Method, you need to see the answer to your questions. 3. generated/cocos2dxapi. all js errors. 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. several common cocos2d-x units in C ++ and JS (jsb_coco2d.js) C ++ JavascriptCCLOGcc. logccc3cc. c3bccc4cc. c4bccc4fcc. c4fccpcc. pCCSize (w, h) cc. sizeCCRect (x, y, w, h) cc. rect 5. type Javascript is a weak type language. No CCArray or CCDictionary is available here, because any Javascript Object has the basic features of arrays and dictionaries. 6. when writing C ++ dynamically, I envy the dynamic features of Objective-c. For example, NSLog (@ "% @", obj) can output the description of an 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 demo, will solve your 90% questions.

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.