Cocos2D中:如何动画落下的砖头到网格 [英] COCOS2D: how to animate falling bricks into a grid
问题描述
我想在比赛开始时以动画41砖块落入一个网格6X7从屏幕顶部,但到目前为止,我刚刚已经能够使砖块倒下的同时位置。如果我删除动画部分,那么所有的砖块出现在网格中。砖应属于打倒previous砖后一两毫秒的创建步骤的效果。
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];
}
}
}
推荐答案
您可以使用延时每块砖,像这样
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]]];
然后创建一个randon时间,将其设置为WAITTIME变量。
然后每次通话将移动一砖一瓦,然后等待,然后再次做到这一点。
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.
希望它帮助!
这篇关于Cocos2D中:如何动画落下的砖头到网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!