1
votes

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 ?

1

1 Answers

1
votes

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.