Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a count down timer for cocos2d?

Tags:

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?

like image 245
Md Nasir Uddin Avatar asked Jan 15 '09 13:01

Md Nasir Uddin


People also ask

What programming language does Cocos2D use?

Cocos2D suits companies that decide to build games and interactive apps that are 2D, developed with the C++ programming language, JavaScript, C# and Lua, and can be played on both Android and iOS mobile technologies, as well as across all the main operating systems (Windows, Mac, Linux).


1 Answers

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
}
like image 196
JustinB Avatar answered Sep 21 '22 18:09

JustinB