我有两个精灵。两者都应该动画。但是sprite1应该首先动画,并且在完成sprite1的动画之后,应该启动sprite2动画。我可以说一个精灵从某个时间开始运行并在某个时间结束吗?这是我的问题。请解释我该怎么做。 谢谢。
答案 0 :(得分:2)
最简单的方法是通过CCActions,特别是让CCCallFunc操作调用代码中的方法,以便在sprite1动画完成后立即启动sprite2动画。然后使用CCSequence创建CCAnimate的动作序列,然后创建CCCallFunc。
// Lets say you have this as the CCAnimation for Sprite1
CCAnimation *sprite1Animation = [CCAnimation …]…
// then you setup the animate action:
// Suppose you have a method called -(void)startSprite2Animation {} which starts the sprite2 animation :-)
id animateAction = [CCAnimate actionWithAnimation:sprite1Animation restoreOriginalFrame:NO];
id callSprite2Animation = [CCCallFunc ctionWithTarget:self selector:@selector(startSprite2Animation)];
id animateAndActionSequence = [CCSequence actions: animateAction, callSprite2Animation,nil];
[sprite1 stopAllActions]; // If you have actions running
[sprite1 runAction:animateAndActionSequence];
// See more on Cocos2D actions here: http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions