how to tell if ccanimate is finished?


#1

I have been working on this for few hours, can’t get anything to work.

I want to create an explosion effect, so I create the explosion animation, create the ccanimate and let a explosion sprite to run that ccanimate via runAction();

But when the Action is done, I should be able to detect and delete the sprite.

but CCAction~~>isDone doesn’t work at all.
When the animation is finished, CCAction~~>done() will still stay false.

@ cocos2d::CCSprite *sprite = (cocos2d::CCSprite*) children~~>objectAtIndex;
cocos2d::CCAction *action = NULL;
if ))
{
if) // can’t work!
{
sprite~~>removeFromParentAndCleanup(true);
}
}@

I looked up the ccanimate manual, there is no callback function, no indicator function that tells the action is done.

what am i suppose to do?


#2

here is how I create the animation:

@
cocos2d::CCArray heroEffect = new cocos2d::CCArray;
for
{
char name[256] = ;
sprintf;
cocos2d::CCSpriteFrame
frame = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()>spriteFrameByName;
heroEffect
>addObject(frame);
}
m_clan1ship1blurb_10fr = new cocos2d::CCAnimation();
m_clan1ship1blurb_10fr~~>initWithSpriteFrames;
m_clan1ship1blurb_10fr~~>setRestoreOriginalFrame(false);
m_clan1ship1blurb_10fr~~>setLoops;@
here is how I create the sprite:
@
cocos2d::CCAnimate *theAnim = cocos2d::CCAnimate::create;
theAnim~~>setTag(1234);

cocos2d::CCSprite *effectSprite = new cocos2d::CCSprite();

effectSprite~~>initWithSpriteFrameName;
effectSprite~~>setPosition(cocos2d::CCPoint(body1~~>getPosition.x, body1~~>getPosition().y));

((cocos2d::CCSpriteBatchNode*)getChildByTag(TagEffect))>addChild;
effectSprite
>runAction(theAnim);@


#3

You can try using a CCSequence and make it so that after playing the animate action, you call a CCCallFunc action.

void HelloWorld::animateSprite( CCSprite * p_Sprite ) {
   CCAnimate * animAction = CCAnimate::create( getAnimation() );
   CCCallFunc * callFunc = CCCallFunc::create( p_Sprite, callfunc_selector( HelloWorld::doEndBomb ) );
   p_Sprite -> runAction( CCSequence::create( animAction, callFunc, NULL ) );
}

void HelloWorld::animateSprite( CCObject * p_Sender ) {
   p_Sender -> removeFromParentAndCleanup( true );
}

#4

Is there a better solution with 3.0?