Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 循环等待_Ios_Objective C_For Loop_Cocos2d Iphone - Fatal编程技术网

Ios 循环等待

Ios 循环等待,ios,objective-c,for-loop,cocos2d-iphone,Ios,Objective C,For Loop,Cocos2d Iphone,我有一个游戏,你有一个射子弹的精灵。我为循环创建了一个,用于更新子弹精灵的y位置 for(int x=0; x<capacity; x++){ int bulletY = 100; [bullet setPosition:ccp(sniper.position.x, bulletY)]; bulletY = bulletY + addition; } 因为我没有选择器。我不能使用[NSThread sleepForTimeInterval:1.0f]因为它没有显示子弹在移动 那么,如果不

我有一个游戏,你有一个射子弹的精灵。我为循环创建了一个
,用于更新子弹精灵的y位置

for(int x=0; x<capacity; x++){
int bulletY = 100;
[bullet setPosition:ccp(sniper.position.x, bulletY)];
bulletY = bulletY + addition;
}
因为我没有选择器。我不能使用
[NSThread sleepForTimeInterval:1.0f]因为它没有显示子弹在移动


那么,如果不使用上述方法,我怎么能稍微延迟一点呢?

声明int-bulletY;作为.h文件中的实例变量。创建新的更新方法

-(void) myUpdate:(ccTime)dt
{
    bulletY++;

    [bullet setPosition:ccp(sniper.position.x, bulletY)];

}
像这样调用新方法,可能是从init调用

[self schedule:@selector(myUpdate:) interval:1.0f]; //1.0f is once per second, change it

在整个游戏中,你需要某种时间系统来更新和绘制精灵。为什么不使用helper方法并使用它调用选择器呢?请阅读Cocos2D中的操作。
[self schedule:@selector(myUpdate:) interval:1.0f]; //1.0f is once per second, change it