COCOS2D:如何将砖块落入网格中的动画
我在游戏开始时尝试制作 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为每个砖块使用延迟,如下所示
,然后创建一个随机时间并将其设置为 waitTime 变量。
然后每次调用都会移动一块砖,然后等待,然后再做一次。
希望有帮助!
you can use a Delay for each brick, something like this
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!