如何在 Cocos2D 中延迟移动精灵



数组中有精灵的数量。 现在我想移动延迟时间为 0.5 的精灵,当时我在下面的代码中使用所有精灵同时掉落,但我想一个接一个地掉落精灵.我也使用 CCDelay 方法,但也没有得到所需的结果。

for (int j = 1; j < [ary count]; j++)
 {
    torpedoOne.position = ccp(160,580);
    id actionMove = [CCMoveTo actionWithDuration:2.0
                                        position:ccp(30 + (j*25),300)];
    id deleay = [CCDelayTime actionWithDuration:1.0];

    [torpedoOne runAction:[CCSequence actions:actionMove,deleay,nil]];
    [self addChild:torpedoOne];
 }

首先,for循环在动作运行后完成,以便所有精灵在同一时间具有相同的ACION。

每次进入 for 循环时如何运行操作?

我也是尝试COCOS2D:如何将掉落的砖块动画化到网格中

你的逻辑很奇怪。尝试

for (int j = 0;j<[ary count]; j++{        // gets all objects in ary : 0 to count-1
    torpedoOne = [ary objectAtIndex:j];   // I am assuming this is what you wanted
    torpedoOne.position = ccp(160,580);
    id actionMove = [CCMoveTo actionWithDuration:2.0
                                        position:ccp(30 + (j*25),300)];
    float delayTime = j*0.5f;
    torpedoOne.visible = NO;
    id show = [CCShow action];   // if you want them invisible prior to start move
    id delay = [CCDelayTime actionWithDuration:delayTime];
    [torpedoOne runAction:[CCSequence actions:delay,show,actionMove,nil]];
}

另外,您应该在循环内设置鱼雷。

过了很长时间,我在 cocos2d 中通过特别延迟得到了带有动画的精灵。

   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
                       ^{
                              for (int j = 1; j < [ary count]; j++)
                                {
                                  dispatch_async(dispatch_get_main_queue(),
                                   ^{
                                     torpedoOne.position = ccp(160,580);
                                     id actionMove = [CCMoveTo actionWithDuration:2.0
                                            position:ccp(30 + (j*25),300)];
                                     id deleay = [CCDelayTime actionWithDuration:1.0];

                                     [torpedoOne runAction:[CCSequence actions:actionMove,deleay,nil]];
                                     [self addChild:torpedoOne];
                                     });
                                [NSThread sleepForTimeInterval:delay];
                                }
                    });

最新更新