I have two sprites. Both should animate. But sprite1 should animate first and after completion of the animation of sprite1, sprite2 animation should 开发者_运维问答start. Can I say to a sprite to run from a certain time and end at a certain time ? This is my problems. Please explain how can I do that. Thank You.
On of the easiest ways to do this is via CCActions, in particular having the CCCallFunc action call a method in your code to start up the sprite2 animation as soon as the sprite1 animation finishes. You then use CCSequence to create an action sequence of CCAnimate then 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
精彩评论