API style cocos2d-x
1. In the Cocos2d-x engine, except for the singleton mode, each cocos2d Class has its own static Class * Class: create (...) method. We strongly recommend this method. Sample Code:
Sprite* monster = Sprite::create("Monster.png");monster->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));this->addChild(monster);
2. doSomething ()
This is the most common function name, which is applied everywhere in the Cocos2d-x/-html5 engine. The first word is a verb, and the second word is a noun. For example, replaceScene (CCScene *) and getTexture ().
3. doWithResource ()
It is a variant of the doSomething () method. In initWithTexture (CCTexture *) and initWithFilename (const std: string &), you can often see this function name.
4. onEventCallback ()
When you see a function name similar to void onEnter (), the onAction type indicates that this is a callback function. When certain conditions are raised, other classes call this method.
5. In the Cocos2d-x engine, if you do not find the create (), only the getInstance () method is found, it belongs to the singleton mode class. For example, TextureCache: getInstance (). The structure of the singleton class is destroyInstance ().
6. The Cocos2d-x engine uses many getter and setters to change the attribute value. This usually affects the behavior of objects. For example, _ sprite-> setPosition (ccp (0, 0) moves the genie to the lower left corner. Based on performance optimization, the CCSize reference is returned here, instead of building another CCSize. When this CCSize & is changed, the internal member variables of the object will be affected, so this CCSize & is a constant.
If the property is "read-only", there will be no setProperty (type) method;
If the attribute is a bool value, the setProperty (bool) and isProperty () methods are available. For example, Sprite: isDirty () and Sprite: setDirty (bool bDirty ).
If the property is not a bool value, there will be setProperty (type) and getProperty () methods. For example, void Sprite: setTexture (Texture2D *) and Texture2D * CCSprite: getTexture ().