Cocos2d: How to set a timer

I am developing an application for the iPhone using cocos2d and box2d. In this application, I need to set a timer. The timer will show the remaining time in the hands of the player to achieve the goal ...

how can i do this ..... i drew a scene but not sure how i start how to add a timer ..

thank

+5
source share
2 answers

You can use CCTimer. Similar:

float delay = 1.0; // Number of seconds between each call of myTimedMethod:
CCTimer *myTimer = [[CCTimer alloc] initWithTarget:self 
                             selector:@selector(myTimedMethod:) interval:delay]];

The myTimedMethod: method will be called every second.

+6
source

I would just plan an interval selector. This works in all classes based on CCNode.

Schedule a selector to run once per second:

[self schedule:@selector(timerUpdate:) interval:1];

This method is called once per second:

-(void) timerUpdate:(ccTime)delta
{
  numSeconds++;
  // update timer here, using numSeconds
}

Parceval CCTimer , :

CCTimer *myTimer = [CCTimer timerWithTarget:self
                                   selector:@selector(myTimedMethod:)
                                   interval:delay]];
+18

All Articles