2

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Akarsh M
  • 1,629
  • 2
  • 24
  • 47
  • If I have only a sprite than I can apply the removeChid method for it but in the case of animation I not apply this one on it ... So , what method I use for it ? – Akarsh M Jul 11 '13 at 09:28

3 Answers3

5

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

Community
  • 1
  • 1
OscarLeif
  • 894
  • 1
  • 9
  • 17
3

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);
pktangyue
  • 8,326
  • 9
  • 48
  • 71
0

sprite_name->runAction(Sequence::create(ScaleTo::create(1, 0),RemoveSelf::create(), NULL));

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 02 '21 at 08:54