Significant fps drops when unpausing the view in Spritekit
Asked Answered
H

1

2

I've noticed significant fps drops (framerate drops between 5-10fps), when unpausing the view in SpriteKit. I tried this with empty project (Spritekit game template). Here is the code:

if(!self.view.paused){
        self.view.paused = YES;
        NSLog(@"Paused");
    }else{
        NSLog(@"Unpaused");
        self.view.paused = NO;
    }

If I pause the scene, everything works as expected and frames are steady at 60fps. I am testing this on device.

if(!self.paused){
        self.paused = YES;
        NSLog(@"Paused");
    }else{
        NSLog(@"Unpaused");
        self.paused = NO;
    }

This can make a problem with gameplay when unpausing because some frames will be skipped... Any thoughts what's going on ?

Hendrix answered 17/7, 2015 at 8:20 Comment(0)
C
1

I'm assuming it is dropping temporarily after the un-pause? Or is it always low fps after un-pausing. Is this only happening on iOS 8 or iOS 9. Can you try iOS 9? I'm convinced this might be occurring because after un-pausing it takes Sprite-Kit a little to "warm-up" the rendering cycle. You can try profiling in instruments and see what is happening.

As for a solution, you can try lowering the speed of your SKPhysicsWorld temporarily after un-pausing so the physics don't jump because Sprite Kit has a variable time step and unfortunately that can't be changed. If it's the actions that are jumping, you can try lowering the speed of your SKScene. Ideally you should probably do both.

Additionally, if you only need to worry about actions, you can try only pausing your scene instead of your SKView (but keep in mind your update method will run). Or try temporarily pausing your scene then un-pausing it after un-pausing the SKView.

Other than this, there is really not much else you can do to fix this other than try to prepare for the dropped frames. Definitely report it to Apple if you haven't already.

Below is the class reference for all of these properties.

SKView-paused

If the value is YES, the scene’s content is fixed onscreen. No actions are executed and no physics simulation is performed.

SKScene - speed

The default value is 1.0, which means that all actions run at their normal speed. If you set a different speed, time appears to run faster or slower for all actions executed on the node and its descendants. For example, if you set a speed value of 2.0, actions run twice as fast.

SKScene - paused

If the value is YES, the node (and all of its descendants) are skipped when a scene processes actions.

SKPhysicsWorld - speed

The default value is 1.0, which means the simulation runs at normal speed. A value other than the default changes the rate at which time passes in the physics simulation. For example, a speed value of 2.0 indicates that time in the physics simulation passes twice as fast as the scene’s simulation time. A value of 0.0 pauses the physics simulation.

Clothespin answered 17/7, 2015 at 16:4 Comment(4)
I am testing on iOS 8... This is happening temporarily, and fps become steady in a second or less ... And yes, I got good results when pausing the scene and using additional BOOL property to control update: execution. The thing I haven't tried is to play with speed property (of physicsWorld)... I will try that one, and let you know the results...Hendrix
Nah, no difference as I can tell . Note that this is happening even with empty project, not just in a game (where actions are used). I guess I can fill a radar for this just in case. I guess this is related to Spritekit's "warm-up" the "engine" :) when unpausing the view as you stated. At least pausing the scene works as expected. Thanks for the answer.Hendrix
@Hendrix Ahh that's too bad. I'll try to test later and see if I can come up with a different solution. I can also try running on iOS 9 and i'll let you know if they fixed it.Clothespin
It would be nice if you do that. Thanks!Hendrix

© 2022 - 2024 — McMap. All rights reserved.