Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timers in Sprite Kit

Tags:

sprite-kit

I don't have experience with Sprite Kit. I was wondering is there something similar to Cocos2D schedulers in Sprite Kit ? If no, what should be used NSTimer is the only option? I guess if the only option is using NSTimer we manually need to handle case when application is in background. Thank you.

like image 988
User1234 Avatar asked Feb 15 '14 22:02

User1234


1 Answers

To achieve functionality similar to cocos scheduler you can use SKAction.

For example for the to achieve something like this

[self schedule:@selector(fireMethod:) interval:0.5];

using SKAction You would write this

SKAction *wait = [SKAction waitForDuration:0.5];
SKAction *performSelector = [SKAction performSelector:@selector(fireMethod:) onTarget:self];
SKAction *sequence = [SKAction sequence:@[performSelector, wait]];
SKAction *repeat   = [SKAction repeatActionForever:sequence];
[self runAction:repeat]; 

It isn't best looking, and lacks some flexibility of CCScheduler, but it will pause upon backgrounding, pausing scene/view etc. + it is like playing with LEGOs :)

like image 169
Dobroćudni Tapir Avatar answered Oct 19 '22 13:10

Dobroćudni Tapir