views:

14

answers:

1

I have an array randomAlphabets which contains CCSprite objects. I need to start animation on these objects. The randomAlphabets array (NSMutable) can contain max of 4 elements. I am running a loop and then starting the animation. Is this the correct way?

-(void) startAnimation:(CCSprite *) sprite
{

    [self generateRandomCoordinates]; 

    id actionMove = [CCMoveTo actionWithDuration:3.0 position:ccp(x,y)];
    id actionRotate = [CCRotateBy actionWithDuration:0.0 angle:rotateBy]; 

    id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(finishedMoving:)]; 

    [sprite runAction:[CCSequence actions:actionMove,actionRotate, actionMoveDone, nil]];

}

-(void) addAlphabetsOnScreen 
{
    for (int i=0; i<=randomAlphabets.count -1; i++) {

        CCSprite *sprite = [randomAlphabets objectAtIndex:i]; 

        [self generateRandomCoordinates];       

        sprite.position = ccp(x,y); 
        [self addChild:sprite]; 

        [self startAnimation:sprite]; 
    }

}
+1  A: 

Sure, why not?

If have performance issues or sprites not starting their anims simultaneously, you might want to "prepare" the sequences for each sprite in one step (maybe after loading the level) and then just kick them all of in another step. 4 Sprites starting at the same time seems not too tough though.

Toastor