4

Is it possible to purposely slow down the SpriteKit scene's FPS? I was thinking if this is possible to make debugging of my game easier.

GeneCode
  • 7,545
  • 8
  • 50
  • 85

2 Answers2

6

You can do something like this as well (as an addition to crashoverride777's answer) by slowing down nodes or physics:

To make nodes going into slow-mo (you can do this per node):

self.speed = 0.2 //where self is a scene

or to do the same with physics:

self.physicsWorld.speed = 0.2 //where self is a scene
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • This is not robust solution. Especially if you have particles in the game and when you have lots of sprites (looping thru sprites could hit performance issues). But thanks for your answer. – GeneCode Jan 23 '17 at 03:15
  • Why would you loop through sprites in any case in order to slow them? You change the speed of their parent or change the speed of a scene. @GeneCode – Whirlwind Jan 23 '17 at 05:23
  • Also this method gives you possibility to separately slow down a physics world, a complete node tree, or a single node for example... – Whirlwind Jan 23 '17 at 05:28
  • I see. Does that mean the particles will be also be slowed down using this method? – GeneCode Jan 23 '17 at 06:30
  • @GeneCode Nope. But neither solution of these two solves that. – Whirlwind Jan 23 '17 at 07:29
  • Ok. Do you have idea how to slow everything including particles? – GeneCode Jan 23 '17 at 07:50
  • Not really @GeneCode – Whirlwind Jan 23 '17 at 07:54
  • 1
    @GeneCode I mean there is a property on SKEmittetNode called particleSpeed, but that will change the behaviour of your particle as well. – Whirlwind Jan 23 '17 at 08:32
  • 1
    @GeneCode I made a question inspired by your question, so you may want to track it http://stackoverflow.com/q/41805786/3402095 – Whirlwind Jan 23 '17 at 16:39
4

You can change the FPS value of your SKView when you load the first scene from your GameViewController.

Something like:

if #available(iOS 10.0, *) { 
     skView.preferredFramesPerSecond = 30 // 30 FPS 
} else {
     skView.frameInterval = 2 // Deprecated (1 default = 60FPS so 2 would = 30 FPS)
     skView.preferredFrameRate = ... // Deprecated
}

As Whirlwind so kindly pointed out in his answer:

"Also, this will not slowdown anything, you just skip frames you are seeing, eg. if you have a node that moves from point A to point B in 5 seconds, and you change preferredFrameRate to 30fps, the node will move from A to B still in 5 seconds, rather than 10. The only change you will see, is that some frames are skipped."

SKView API reference here

Community
  • 1
  • 1
crashoverride777
  • 10,581
  • 2
  • 32
  • 56
  • Good answer . Also `frameInterval` is deprecated as explained by the current `SKView` class: `/* Deprecated, please use preferredFramesPerSecond. Number of frames to skip between renders, defaults to 1 (render every frame) Actual requested rate will be preferredFramesPerSecond / frameInterval. */ @available(iOS, introduced: 7.0, deprecated: 10.0) open var frameInterval: Int` – Alessandro Ornano Jan 20 '17 at 12:22
  • 1
    @GeneCode As it can be seen from Alessandro's comment, this property is available only for iOS 10 and above, so you will have to use something like this : `if #available(iOS 10.0, *) {...}` if your deployment target is < 10. Also, this will not slowdown anything, you just skip frames you are seeing, eg. node that moves from point A to point B in 5 seconds, and you change preferredFrameRate to 30fps, the node will move from A to B still in 5 seconds, rather than 10. The only change you will see, is that some frames are skipped. – Whirlwind Jan 23 '17 at 08:49
  • Hey thanks for your comment. I will update my answer – crashoverride777 Jan 23 '17 at 11:46