ios - Cocos2d: How to create a global timer? -


i'm doing cocos2d project i'm newbie in. please bear me.

when creating timer in game use throughout app.

-(void)onenter {     [super onenter];     [self.timercountdown invalidate];           self.timercountdown = [nstimer scheduledtimerwithtimeinterval:1 target:self selector:@selector(timercountdown:) userinfo:nil repeats:yes];  }  -(void) timercountdown: (nstimer*) timer {      self.secondsleft--;  } 

apparently when click game go view, onenter got called again triggers timer count again.

so question how should approach problem make timer continues same counts i'm in different views 2 mins.

if purely ios app, thought 2 options. first 1 pass through segue , second 1 use userdefaults.

however don't think same cocos2d. there no segue well!

any advice grateful. thanks.

don't use nstimer. instead use delta times passed update: method.

@interface yourclass () {     cgfloat _timeout; } @end  @implementation yourclass  -(void)onenter {     [super onenter];     _timeout = 30.0; }  - (void)update:(cctime)deltatime {     _timeout -= deltatime;     if (_timeout < 0.0) {         // thing         _timeout = 30.0;     } } 

that repeating timeout; you'll need variable single-shot timeout.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -