2

在 SpriteKit 中取消暂停视图时,我注意到 fps 显着下降(帧率下降 5-10fps)。我用空项目(Spritekit 游戏模板)尝试了这个。这是代码:

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

如果我暂停场景,一切都会按预期运行,帧数稳定在 60fps。我正在设备上对此进行测试。

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

这可能会在取消暂停时导致游戏出现问题,因为某些帧会被跳过......有什么想法吗?

4

1 回答 1

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.

于 2015-07-17T16:04:53.900 回答