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

查看:86
本文介绍了在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天全站免登陆