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?
Asked
Active
Viewed 528 times
0
-
You may want to look into the Particle System functionality of cocos2d. It sort of sounds like you are trying to build something that may already exist. – dqhendricks Mar 21 '13 at 19:53
1 Answers
2
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]];
}

busta117
- 526
- 4
- 8