How can I create a count down timer for cocos2d?

Md Nasir Uddin picture Md Nasir Uddin · Jan 15, 2009 · Viewed 28.4k times · Source

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?

Answer

JustinB picture JustinB · Mar 3, 2009

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
}