COCOS2D: how to animate falling bricks into a grid

≯℡__Kan透↙ 提交于 2019-12-24 19:28:16

问题


I'm trying in the beginning of the game to animate 41 bricks to fall into a grid that is 6x7 from the top of the screen but so far I've just been able to make the bricks to fall down at the same position. If I remove the animation part then all bricks appear on the grid. The bricks should fall down with a millisecond or two after the previous brick to create the effect of steps.

I know that the position is the issue but I don't know how to fix it.

-(void)AnimateBricksFalling
{
    self.allowTouch = NO;
    for(int i =0; i< GRID_WIDTH ; i++)
    {
        for(int j =0; j< GRID_HEIGHT ; j++)
        {
            Bricks * d = grid[i][j];
            d.mySprite.position = ccp(168,1000); //the position is the issue, making all the bricks to fall down to the same position
            CCMoveTo *move = [CCMoveTo actionWithDuration:0.5 position:ccp(168,91)]; //the position is the issue, making all the bricks to fall down to the same position
            [d.mySprite runAction: move];
        }
    }
}

回答1:


you can use a Delay for each brick, something like this

 [d.mySprite runAction: [d.mySprite runAction: [Sequence actions:
[DelayTime actionWithDuration: waitTime],
[CCMoveTo actionWithDuration:0.5 position:ccp(168,91)],
nil]]];

And then create an randon time and set it to the waitTime variable. Then each call will move one brick, then wait, and do it again.

Hope it helps!



来源:https://stackoverflow.com/questions/7631172/cocos2d-how-to-animate-falling-bricks-into-a-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!