CCSPrite 's init() method excued twice in all CCSprite's static method

CCSPrite 's init() method excued twice in all CCSprite's static method
0.0 0


I had checked the cocos2d-x source code and I found that CCSPrite ‘s init() method excued twice in all CCSprite’s static method.
Ssuch as:
and so on.
beacuse what they do is new a CCSprite at the begin of the method,and there is a init() method in the CCSprite Constructor.
go on,
all of these static method end with initTexture()method, and in this method there appears a init() method again.
so, init() method excuted twice.
What I want to say is that why not virtual init() method ?
if so ,we can wirte my code like this in child of CCSPrite
bool CCSpriteChild::init() { if(!CCSprite::init()) { return false; } some init thing of child }
and then remove the init() method in CCSprite’ constructor method

last we can we can use a Macro to let all CCSPrite’s child implemt all CCSprite::spriteWithxxx like static method:
#define LAYER_SPRITE_WITH_SPRITE_FRAME_NAME(layer) static layer* spriteWithSpriteFrame(CCSpriteFrame pSpriteFrame) ; static layer spriteWithSpriteFrameName(const char *pszSpriteFrameName)


mm, to make CCSprite::init() a virtual method sounds reasonable.

but in your code, CCSpriteChild::init() will be called in “new layer();” and “pobSprite->initWithSpriteFrame(pSpriteFrame))” no matter CCSprite::init() is virtual or not, right?
ofcourse, here layer should be a derived class.


since we had remvoed the CCSprite::init() method in CCSprite::CCSprite() constructor then CCSpriteChild::init() method will not be called in “new layer()”.
In the other hand , chance are the CCSpriteChild::init() method will be called in “CCSprite::initWithSpriteFrame” or we can say “CCSprite::initWithTexture”.

so ,only virtual init() method ,the Macro I posted will works.
use the Macro to make us call method like this “CCSpriteChild::spriteWithXXX”


@ hex lee
I agree with you.
#698 is created for it.
Thank you.