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.
views:
352answers:
1
+1
A:
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
Rod
2010-03-18 14:22:33
Thank you for that. At last I have got one answer for this. I will use in my program and If have any problems I would post to you.
srikanth rongali
2010-03-19 03:53:56
Hi, Thank you very much. It worked as I needed.I think you are member from today. Have a good time here.Thank you again.
srikanth rongali
2010-03-19 04:38:14