Ios 如何在cocos2d中延迟移动精灵?
我有许多精灵在阵列中。现在我想移动延迟时间为0.5的精灵。我使用下面的代码,当时所有精灵都同时下落,但我想一个一个地下落精灵。我也使用CCDelay方法,但也没有得到要求的结果Ios 如何在cocos2d中延迟移动精灵?,ios,cocos2d-iphone,Ios,Cocos2d Iphone,我有许多精灵在阵列中。现在我想移动延迟时间为0.5的精灵。我使用下面的代码,当时所有精灵都同时下落,但我想一个一个地下落精灵。我也使用CCDelay方法,但也没有得到要求的结果 for (int j = 1; j < [ary count]; j++) { torpedoOne.position = ccp(160,580); id actionMove = [CCMoveTo actionWithDuration:2.0
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(int j=1;j<[ary count];j++)
{
1.位置=ccp(160580);
id actionMove=[CCMoveTo actionWithDuration:2.0
职位:ccp(30+(j*25),300)];
id delay=[CCDelayTime actionWithDuration:1.0];
[一次运行操作:[CCSequence操作:actionMove、Delay、nil]];
[自我添加的孩子:一个];
}
首先,for循环在操作运行后完成,以便所有精灵在同一时间具有相同的acion
每次进入循环时如何运行操作
我也试试看,你的逻辑很奇怪。试一试
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]];
}
for(int j=0;j经过很长一段时间后,我在cocos2d中通过特殊的延迟一个接一个地获得了带有动画的sprite
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];
}
});
调度异步(调度获取全局队列(调度队列优先级低,0),
^{
对于(int j=1;j<[ary count];j++)
{
dispatch\u async(dispatch\u get\u main\u queue(),
^{
1.位置=ccp(160580);
id actionMove=[CCMoveTo actionWithDuration:2.0
职位:ccp(30+(j*25),300)];
id delay=[CCDelayTime actionWithDuration:1.0];
[一次运行操作:[CCSequence操作:actionMove、Delay、nil]];
[自我添加的孩子:一个];
});
[NSThread sleepForTimeInterval:延迟];
}
});