0

When I setup a SpriteKit action like so:

action = [SKAction sequence:@[[SKAction performSelector:@selector(update) onTarget:self],[SKAction waitForDuration: 1.0f/60.0f]]];

Will my selector be called at 60fps even if the game is only running at 30fps? Or will it max out at whatever the game's frame rate currently is?

BGreenstone
  • 260
  • 1
  • 11
  • Yes, the selector will get called 60 times per second, regardless of the framerate. (This has to be called using repeatForever) – ZeMoon Jul 18 '14 at 13:48

1 Answers1

0

It should be called in synch with your frame rate. The SKScene reference states that for didEvaluateActions methods:

Do not call this method directly; it is called exactly once per frame, so long as the scene is presented in a view and is not paused.

This is also in line with the update loop diagram in the SK programming guide. Sprite Ykit has no "fixed" update method that always runs at a fixed interval.

If waitForDuration were not bound to framerate this would violate the documented update loop behavior.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Well, there's one issue with the way performSelector works in an SKAction. If I *don't* put the waitForDuration in there the app will hang in an infinite loop, so that would suggest that the action is not necessarily called once per frame. I even spoke directly to Apple about this, and they said that yes, I needed to put the delay in there to avoid an infinite loop. However, I forgot to ask them what rate it would be called, 60fps or at the actual frame rate. – BGreenstone Jul 18 '14 at 17:53
  • performSelector is an "instant" action, meaning it has no duration which would explain why looping it will cause the infinite loop. – CodeSmile Jul 18 '14 at 22:33