I am using the CCAnimation class for using animation with more than one CCSprite . What I want is :
" Just Remove the sprite after the animation complete "
If anybody work on this, Please Let me Know. What should I do for it.
I am using the CCAnimation class for using animation with more than one CCSprite . What I want is :
" Just Remove the sprite after the animation complete "
If anybody work on this, Please Let me Know. What should I do for it.
I know the solution of pktangyue works but I want to add a new answer because this is deprecated in cocos2d-x V3.x Please read the final way to do this it's more easy
Node *nodeSprite =(Node*)layer->getChildByName("BFL_Ready_Label");
MoveTo* animation = MoveTo::create(1.0f,Point(Director::getInstance()->getWinSize().width/2,Director::getInstance()->getWinSize().height*1.5));
CallFunc* animationDone = CallFunc::create(bind(&Node::removeFromParent,nodeSprite));
Sequence* sequence = Sequence::create(animation,animation,NULL);
node->runAction(Sequence);
And like the previous answer using a Sprite.
MoveTo* animation = MoveTo::create(1.0f,Point(Director::getInstance()->getWinSize().width/2,Director::getInstance()->getWinSize().height*1.5));
CallFunc::create(bind(&Sprite::removeFromParent,m_sprite));
Sequence* sequence = Sequence::create(animation,animation,NULL);
m_sprite->runAction(sequence);
Using this the compiler will not tell that you're using deprecated methods. I hope this will useful.
I update this answer because there's a much easy way to do this when you create a sequence just add the RemoveSelf::create RemoveSelf it's an action so you can add it to the sequence it will destroy the sprite or Node after the animation is complete.
Sequence* sequence = Sequence::create(animation,animation,RemoveSelf::Create(),NULL);
And that's the easy way to destroy the object after the animation is completed this is very usefull in particles
Suppose m_action
is your animation and m_sprite
is you sprite node.
Then you can create a CCSequence
action, with a CCCallFunc
action in the final, like the following code:
CCSequence* seq = CCSequence::create(action,
CCCallFunc::create(m_sprite, callfunc_selector(CCSprite::removeFromParent),
NULL);
m_sprite->runAction(seq);
sprite_name->runAction(Sequence::create(ScaleTo::create(1, 0),RemoveSelf::create(), NULL));