2012-08-07 88 views

回答

2

如果您使用Cocos2D for iphone,則不得使用NSTimer。

documentation,你應該使用schedule:interval:方式類似:

[self schedule: @selector(tick:) interval:1.0f]; 

- (void) tick: (ccTime) dt 
{ 
    //... 
} 
+0

嗯,你__can__使用的NSTimer,雖然強烈勸阻:) – tallen11 2012-08-07 18:43:18

3

您可以使用

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats 

一秒鐘:

NSTimer *yourTastTimer = scheduledTimerWithTimeInterval:1 target:yourTarget selector:@selector(yourMethod) userInfo:nil repeats:YES; 

您可以查看文檔NSTimer瞭解詳情。

編輯

您可能還需要檢查this answer

0

如果您使用CCSprite,他們有一個計劃方法,它可能會伎倆。 基本上做主循環。 您也可以在主循環中保留一個代碼,並檢查這是股票代碼%60 == 0。 然後調用你的動作動作。

我讀了NSTimer與cocos2d here不鼓勵。