[self goToStage:currentStage];
[actor deathAnimation];
我有这两种方法。我想依次称它为一个接一个。在第二个开始之后完成一个。
//this method used in nsobject subclass
-(void)deathAnimation {
//Play death animation
}
//this method in cclayer subclass
-(void)goToStage:(int)stage {
//changing scene
}
在特定事件中我的勾选功能我想在seqeuence中调用
我使用以下代码但不能正常工作
[CCSequence actions:[CCCallFunc actionWithTarget:actor selector:@selector(deathAnimation)], [CCDelayTime actionWithDuration:4.0], [CCCallFuncN actionWithTarget:self selector:@selector(goToStage:)], nil];
Now what i do? Please tell me.. Is there something wrong?
答案 0 :(得分:1)
在你的界面中定义一个块,例如。
typedef void(^MyCompletion)(void);
编辑您deathAnimation
以将块参数视为
- (void)deathAnimationWithCompletion:(MyCompletion)finish {
//..death animation
//...
//when animation finishes
finish(); // This will call your completion block
}
将此方法称为
[self deathAnimationWithCompletion:^{
[self goToStage:2];
}];
您可以在Ray Wenderlichs fantastic blog.
上阅读块希望它有所帮助!
根据评论编辑
在cocos2d中,我认为你也可以制作一个这样的序列
id aFuncCall = [CCCallFunc actionWithTarget:self selector:@selector(deathAnimation)];
id antoherFuncCall = [CCCallFunc actionWithTarget:self selector:@selector(goToSecondStange:)];
CCSequence *sequence = [CCSequence actions:aFuncCall,anotherFuncCall, nil];
[self runAction:sequence];
但我的cocos2d编程技巧有点过时,所以不确定这是否有效......
答案 1 :(得分:1)
您可以使用CCDelayTime(用于提供延迟)和CCCallBlock来传递要调用的方法,如下所示:
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:1],
[CCCallBlock actionWithBlock:^{[self goToStage:currentStage];}],
[CCDelayTime actionWithDuration:1],
[CCCallBlock actionWithBlock:^{[actor deathAnimation}], nil]];
答案 2 :(得分:0)
你可以打电话
[演员死亡动画];
如果您需要等待一段特定的时间,可以在goToStage中放置一个延迟计时器。