About Static Constructor API Changes in cocos2d-x v2.0¶
Previously, we had OBJ-C style API to create objects.
For example, creating a sprite:
CCSprite* pSprite = CCSprite::spriteWithFile ("filename.png");
Now, to create an object, the only constructor name you need to remember is ‘create’.
There are ‘CCSprite::create’,‘CCNode::create’,‘CCMoveTo::create’,‘CCCallfunc::create’and so on.
CCSprite spr = CCSprite::create;
CCMoveBy* act1 = CCMoveBy::create);
CCMoveBy* act2 = act1~~>reverse;
CCFiniteTimeAction act3 = CCSequence::create(act1, act2, NULL);
CCRepeat* act4 = CCRepeat::create(act3, 2);
All objects created from ’XXX::create ()’ are autorelease object and they does not need to be released unless you manually retained it.
Although we have added the ‘create’ API for most classes, we kept old obj-c style API too.
In addition, we marked all old obj-c API with ‘@deprecated’, and added a marco CC_DEPRECATED_ATTRIBUTE at the beginning of old API which will warn you during compilation if
you are using an old api to create object. We strongly advise you to use the new API, since old API may be discarded sooner or later.
var sp = cc.Sprite.create("filename.png");
Create methods also have been used in Lua-Bindings:
local sp = CCSprite:create("fileName.png")