I have an array of sprites. I want to loop through the array and tell each spirite to move a certain distance at a random angle, and fade out while doing so. Preferably with easing. Is there a way to set up a sequence to do this? Can you have a mutable sequence where you can add actions as you loop through the sprite array, and then run the sequence once you're done adding all the actions?
0
votes
1 Answers
2
votes
I don't understand your question so well but maybe this example can help you:
CCArray *spritesArray; //array with sprites
float timeToMove = 1.0;
float timeToRotate = 1.0;
float timeToFadeOut = 1.0;
CGPoint initialMovePos = CGPointMake(100, 100);
for (int i = 0; i<[spritesArray count]; i++) {
id moveDistance;
if (i == 0) {
moveDistance = [CCMoveTo actionWithDuration:timeToMove position:initialMovePos];
}else{
CGPoint lastSpritePos = ((CCSprite *)[spritesArray objectAtIndex:(i-1)]).position;
moveDistance = [CCMoveTo actionWithDuration:timeToMove position:ccpAdd(lastSpritePos, CGPointMake(10, 10))];
}
float angleToRotate = random()%360;
id rotateAction = [CCRotateTo actionWithDuration:timeToRotate angle:angleToRotate];
id fadeOutAction = [CCFadeOut actionWithDuration:timeToFadeOut];
CCSprite *sprite = [spritesArray objectAtIndex:i];
[sprite runAction:[CCSpawn actions:moveDistance,rotateAction,fadeOutAction, nil]];
}