开发者

Moving Sprites (more then 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"] f开发者_运维问答loatValue];
    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 use above code in my application. But I don't require this method.

Above code is for Moving the sprite.

I have placed here above code just because You can imagine what do 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 move all sprites all together at once.

Why Required ? :

You might have seen tetris game.

If bottom most row is complete, then all above rows move down by step one.

I want to do the same.

How?


I have gone through following link.

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

The answer is following.

Spawn

The Spawn action lets you run several actions at the same time. The duration of the Spawn action will be the duration of the longest sub-action.

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

[sprite runAction:action];


Try using concurrent NSThreads, one for each sprite that needs to be moved.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜