2014-06-28 61 views
-2

我有一個遊戲,你有一個子彈射出的精靈。我創建了一個for循環,用於更新子彈精靈的y位置。等待在一個循環中

for(int x=0; x<capacity; x++){ 
int bulletY = 100; 
[bullet setPosition:ccp(sniper.position.x, bulletY)]; 
bulletY = bulletY + addition; 
} 

但這幾乎在瞬間完成。我想展示這顆子彈。我是在循環 年底想我可以有一個等待,但我不能使用

[NSTimer scheduledTimerWithTimeInterval:0.5f 
           target:self 
      selector: @selector(doSomething:) 
          userInfo:nil 
          repeats:NO]; 

,因爲我沒有選擇。我不能使用[NSThread sleepForTimeInterval:1.0f];,因爲它不顯示子彈移動。

那麼我怎麼能延遲一點而不使用上述?

+0

您將需要某種時間系統來完成整個遊戲,並且相應地更新和繪製小精靈。 – FunctionR

+0

爲什麼不使用輔助方法並用它選擇器調用它? – vikingosegundo

+3

閱讀有關Cocos2D中的操作。 –

回答

0

Declare 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