开发者

What is the best way to start Cocos2d Animation of Multiple Sprites?

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,开发者_JS百科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]; 
    }

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜