CCFiniteTimeAction *seq = CCSequence::actions(
CCMoveTo::actionWithDuration(1.0f, CCPoint(size.width / 2,pSprite~~>getContentSize.height / 2)),
CCDelayTime::actionWithDuration,
CCMoveTo::actionWithDuration.height / 2)),
NULL);
pSprite~~>runAction(seq);
//this~~>removeChild;
But I want to know how I can release the memory, if I uncomment the following line
this~~>removeChild(pSprite, false);
The sprite don’t appear in the screen.
How I can retain it and release it after the CCMoveTo?
The solution above would work, but I think it could be over kill re-writing all that functionality.
My way of doing this would be to declare a quick remove function like so:
Header:
void RemoveChildSeq(CCObject* pObj);
Main declaration:
void ClassName::RemoveChildSeq(CCObject* pObj)
{
//there should be more error checking in here to check that it is a child etc.
this->removeChild(pObj, false);
}
Then it is as simple as calling this as an action in your sequence:
//this may be CCCallFuncO::actionWithTarget depending on your release of cocos2d-x
CCAction* removeChild = CCCallFuncO::create(this, callfuncO_selector(ClassName::RemoveChildSeq), pSprite);
I use the CCCallFuncN with the callfuncN_selector.
The CCCallFuncN it’s better than CCCallFuncO, because the callfuncO_selector need 3 parameters and the callfuncN_selector need only 2 parameters.
It doesn’t matter for simple actions, but in general case you can’t reuse actions because each action object stores progress of it’s application. You need to make a copy before applying.
Or this solution, but you can’t use this for removeFromParentAndCleanup(false), only for removeFromParentAndCleanup(true).
callfuncN_selector will pass pointer of mysprite as bool argument.