COCOS2D:如何将砖块落入网格中的动画

发布于 2024-12-08 09:32:25 字数 741 浏览 1 评论 0原文

我在游戏开始时尝试制作 41 块砖块的动画,使其落入距屏幕顶部 6x7 的网格中,但到目前为止,我只能使砖块在同一位置落下。如果我删除动画部分,那么所有砖块都会出现在网格上。砖块应在前一块砖块落下一两毫秒后落下,以产生台阶效果。

我知道这个位置是问题所在,但我不知道如何解决。

-(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];
        }
    }
}

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];
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-12-15 09:32:25

您可以为每个砖块使用延迟,如下所示

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

,然后创建一个随机时间并将其设置为 waitTime 变量。
然后每次调用都会移动一块砖,然后等待,然后再做一次。

希望有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文