Moving sprites (more than one) at a time

From my question here,


http://iphonegamedev.stackexchange.com/questions/82/moving-sprites-more-then-one-at-a-time


-(void)moveBox:(NSTimer*)myTimer{
    float endx=[[[myTimer userInfo] valueForKey:@"endX"] floatValue];
    float endy=[[[myTimer userInfo] valueForKey:@"endY"] floatValue];
    float timing=[[[myTimer userInfo] valueForKey:@"timeForMove"] floatValue];
    Sprite *sp=(Sprite*)[[myTimer userInfo] valueForKey:@"objSprite"];
    [sp runAction: [MoveBy actionWithDuration:timing position:ccp(endx,endy)]];
}

      

I am using the code above in my application. But I don't require this method.

The above code is for moving the sprite.

I posted the code above here because you can imagine what I need.

Now I want to move 10 sprites at a time.

    [sp runAction: [MoveBy actionWithDuration:timing position:ccp(endx,endy)]];

      

Above Line - Moves one sprite at a time.

How to transfer all sprites at the same time.

Why is it necessary?

You may have seen the game of Tetris.

If the bottom line is more complete, all of the above lines are skipped to the first step.

I want to do the same.

How?

+2


source to share


2 answers


I have looked at the following link.

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions_composition

The answer is as follows.

Spawn



The Spawn action allows you to run multiple actions at the same time. The duration of the Spawn will be the duration of the longest sub-action.

id action = [Opening actions: [JumpBy actionWithDuration: 2 position: ccp (300,0) height: 50 jumps: 4], [RotateBy actionWithDuration: 2 angle: 720], zero];

[sprite runAction: action];

+2


source


Try using parallel NSThreads, one for each sprite you want to move.



+1


source







All Articles