在 Spritekit 中取消暂停视图时 fps 显着下降 [英] Significant fps drops when unpausing the view in Spritekit

查看:13
本文介绍了在 Spritekit 中取消暂停视图时 fps 显着下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;
    }

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

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 ?

推荐答案

我假设它在取消暂停后暂时下降?或者在取消暂停后它总是低fps.这只发生在 iOS 8 或 iOS 9 上.你能试试 iOS 9 吗?我确信这可能会发生,因为在取消暂停后,Sprite-Kit 需要稍微预热"渲染周期.您可以尝试在仪器中进行分析,看看发生了什么.

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.

至于解决方案,您可以尝试在取消暂停后暂时降低 SKPhysicsWorldspeed,这样物理就不会跳跃,因为 Sprite Kit 具有可变时间一步,不幸的是,这是无法改变的.如果是跳跃的动作,你可以尝试降低 SKScenespeed.理想情况下,您应该两者都做.

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.

此外,如果您只需要担心动作,您可以尝试只暂停场景而不是 SKView(但请记住,您的更新方法将运行).或者尝试暂时暂停您的场景,然后在取消暂停 SKView 后取消暂停.

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.

除此之外,除了尝试为丢帧做准备之外,您实际上没有什么可以解决的.如果您还没有,请务必向 Apple 报告.

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-暂停

如果值为 YES,则场景的内容固定在屏幕上.无操作被执行并且不执行物理模拟.

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

SKScene - 速度

SKScene - speed

默认值为 1.0,这意味着所有操作都以它们的速度运行正常的速度.如果您设置不同的速度,时间似乎跑得更快对于在节点及其后代上执行的所有操作,或更慢.例如,如果您将速度值设置为 2.0,则动作运行两次快.

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 - 暂停

SKScene - paused

如果值为 YES,则跳过该节点(及其所有后代)当场景处理动作时.

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

SKPhysicsWorld - 速度

SKPhysicsWorld - speed

默认值为1.0,表示模拟正常运行速度.默认值以外的值会更改时间的速率通过物理模拟.例如,速度值为 2.0表示物理模拟中的时间流逝速度是场景的模拟时间.值 0.0 暂停物理模拟.

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.

这篇关于在 Spritekit 中取消暂停视图时 fps 显着下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆