ios - Decrement Integer Spritekit -


i have project in sprite kit , trying make timer gradually decreases. example if timer float variable set @ 3.0, gradually decrease , @ 0, 3 seconds later. way updates work in sprite kit horrible mess trying integer gradually decrease.

for example:

time+=1; 

if put in update void, increment extremely , differently depending on frames , forth. there way can increment or decrement value @ steady rate no despite fps in sprite kit?

you'd better off getting current time each update , comparing initial time determine when 3 seconds pass.

declare ivar in skscene subclass:

@implementation myscene {     nsdate* _timestamp; } 

when timer starts:

_timestamp = [nsdate timeintervalsincereferencedate]; 

check timer in update pass:

- (void)update:(nstimeinterval)currenttime {     if(_timestamp != nil && currenttime - _timestamp.timeintervalsincereferencedate >= 3.0) {         // perform timer event     }      // other updates } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -