How can I create a count down timer for cocos2d?

后端 未结 6 1630
灰色年华
灰色年华 2020-12-13 15:30

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?

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 16:09

    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
    }
    

提交回复
热议问题