如何在动画结束后获得活动?

时间:2012-06-13 05:34:22

标签: objective-c animation cocos2d-iphone box2d

任何人请告诉我如何在Sprite完成动画后获得一个事件? 我正在使用cocos2d框架工作,

我的代码的某些部分是这样的..

-(void)playerTouchHurdlesOnFlore:(LHContactInfo*)contact
{

    if(!isHurdlesAnimStart)
    {
        isHurdlesAnimStart=YES;

        onGround=NO;

        [player stopAnimation];

        //[player setIsRelativeAnchorPoint:NO];

        // I want to call any event or function after end of the this "Fall_Down" animation.
        [player startAnimationNamed:@"Fall_Down"];

        jumpCounter = 0.3f;
        player.body->ApplyLinearImpulse(b2Vec2(0,2.0f), player.body->GetPosition());
    }

}

如果有的话,请告诉我任何解决方案或给我一些想法,

提前致谢,

:)

2 个答案:

答案 0 :(得分:5)

您只需使用CCCallFunc

创建回调即可
id animation = // any of your action, CCAnimate, CCMoveTo, etc.
id callback = [CCCallFunc actionWithTarget:self selector:@selector(onAnimationEnd)];
id sequence = [CCSequence actionOne: animation two: callback];
[nodeToAnimate runAction: sequence];

当然,您可以使用任何您想要的目标和选择器作为回调

答案 1 :(得分:0)

你能检查sprite和cocoa2d的文档,应该有一个委托方法,如

 - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished

但此方法适用于Core Animation