How can I create a count down timer for cocos2d?(如何为 cocos2d 创建倒数计时器?)
问题描述
I am developing a 2D iPhone game by using cocos2d. I need a countdown timer. How can I create a count down timer in cocos2d?
Not enough rep to upvote Tom, but he's absolutely right. Within the context of this question, NSTimer is the WRONG solution. The Cocos2d framework provides a scheduler that integrates with other game features like Pause/Resume (and most likely uses NSTimer under the hood).
Example from the above link:
-(id) init
{
if( ! [super init] )
return nil;
// schedule timer
[self schedule: @selector(tick:)];
[self schedule: @selector(tick2:) interval:0.5];
return self;
}
-(void) tick: (CCTime) dt
{
// bla bla bla
}
-(void) tick2: (CCTime) dt
{
// bla bla bla
}
这篇关于如何为 cocos2d 创建倒数计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!