Run CCAction on multiple sprites
I have an array of sprites and r开发者_StackOverflow社区un an action on each element. the issue I am having is that the last sprite is the only one that moves.
If I add 3 arrays and iterate through each and use the following
CCRepeatForever *repeat = [CCRepeatForever actionWithAction:moveSequence];
[[row1 objectAtIndex:i] runAction:repeat];
it only move the last drawn sprite.
How does one run an action on every element in an Array?
I need the objects to move at the same time. So all sprites should run the action simultaneously. Is this possible with cocos2d
EDIT*****************
- (void) moveAliens
{
id left = [CCMoveBy actionWithDuration:10 position:ccp(-35, 0)];
id right = [CCMoveBy actionWithDuration:10 position:ccp(35, 0)];
id moveSequence = [CCSequence actions:left, [CCDelayTime actionWithDuration:20], right, [CCDelayTime actionWithDuration:20], nil];
id repeatMoveSequence = [CCRepeatForever actionWithAction:moveSequence];
for (int i = 0; i < [row1 count]; i++)
{
NSLog(@"i is %d", i);
//CCRepeatForever *repeat = [CCRepeatForever actionWithAction:moveSequence];
[[row1 objectAtIndex:i] runAction:repeatMoveSequence];
}
}
Thanks
Place:
left = [CCMoveBy actionWithDuration:10 position:ccp(-35, 0)];
right = [CCMoveBy actionWithDuration:10 position:ccp(35, 0)];
moveSequence = [CCSequence actions:left, [CCDelayTime actionWithDuration:20], right, [CCDelayTime actionWithDuration:20], nil];
repeatMoveSequence = [CCRepeatForever actionWithAction:moveSequence];
inside your for loop. And the variable declarations above it.
You can't use one CCAction for multiple CCNodes simultaneously.
精彩评论