0

任何人请告诉我在 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());
    }

}

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

提前致谢 ,

:)

4

2 回答 2

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];

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

于 2012-06-13T05:47:52.600 回答
0

你能检查一下 sprite 和 cocoa2d 的文档吗,应该有一个像这样的委托方法

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

但此方法适用于 Core Animation

于 2012-06-13T05:54:57.800 回答