Hi!
I am trying to mimic a Flash movieclip in Cocos2D. The typical sequence of events is:
1. Perform a MOVE operation against Sprite1
2. Change the image displayed in Sprite1 when the MOVE above is finished
3. Perform a MOVE operation against Sprite2
4. Perform another animation against Sprite1 when the MOVE operation above is done
Since step 2 cannot be done until step 1 completes, and since step 4 cannot be done until step 3 completes, I use the CCCALLFUNC function inside a CCSEQUENCE to call a new function when the current animation completes. That being said, the code I have created looks like this:
-(void)playPart1
{
CCMoveTo *move = [CCMoveTo actionWithDuration:0.5f position:ccp(100,100)];
CCCallFunc *func = [CCCallFunc actionWithTarget:self selector:@selector(playPart2)];
CCSequence *seq = [CCSequence actions:move,func,nil];
[Sprite1 runAction:seq];
//I can't do anything here because these statements will exec
//before the action above has completed.
//The movieclip must now continue in the playPart2 function.
}
-(void)playPart2
{
[Sprite1 setDisplayFrame:<some frame>];
CCMove *move = <create a new move object like above>
CCCallFunc *func = [CCCallFunc actionWithTarget:self selector:@selector(playPart3)];
CCSequence *seq = [CCSequence actions:move,func,nil];
[Sprite2 runAction:seq];
}
-(void)playPart3
{
//Setup next animation for Sprite1 and run it.
//Call playPart4 when it completes using a sequence.
}
The code continues like this until the movieclip is complete.
My movieclips sometimes are quite long.
Is there a better way to do this?
Thank you!