COCOS2D: how to animate falling bricks into a grid

2019-09-08 11:32发布

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条回答
我命由我不由天
2楼-- · 2019-09-08 12:17

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!

查看更多
登录 后发表回答