SKScene和SKView的暂停属性之间的区别

时间:2023-01-22 20:07:44

I am pausing my SKScene using the following code:

我使用以下代码暂停我的SKScene:

self.paused = YES;

However, according to this answer by Andrey Gordeev, one can also pause a scene using this line:

然而,根据Andrey Gordeev的回答,人们也可以使用这一行暂停一个场景:

self.view.paused = YES;

I would like to understand what difference it would make to call the either (or both) to pause a scene.

我想了解调用其中一个(或两个)暂停一个场景会有什么不同。

2 个解决方案

#1


15  

Pausing SKView stops calling update: method for SKScene.

暂停SKView会停止调用SKScene的update:方法。

Pausing SKScene doesn't do that.

暂停SKScene不会那样做。

I usually pause both SKScene and SKView

我经常暂停SKScene和SKView

EDIT:

As of iOS9 pausing the scene will pause the update: method.

从iOS9暂停场景将暂停更新:方法。

#2


2  

The effect is the same. You still have the paused property on the scene because it's a subclass of SKNode and the scene may need to be paused during transitions, either through the SKView setting that controls whether scenes are paused during transitions or manually.

效果是一样的。您仍然在场景中具有暂停属性,因为它是SKNode的子类,并且在转换期间可能需要暂停场景,可以通过控制场景在转换期间暂停还是手动暂停的SKView设置。

I would wager that pausing the view would also be able to "freeze" a currently running transition, which is about the only thing you can't pause by pausing the scene(s) alone.

我敢打赌暂停视图也能够“冻结”当前正在运行的转换,这是你不能单独暂停场景而暂停的唯一事情。

Therefore pausing the view may also pause all internal timers and draw calls, so a paused view may be better to conserve battery, though that's a guess based on how cocos2d handles a paused director vs paused scene.

因此暂停视图也可能暂停所有内部计时器并绘制呼叫,因此暂停视图可能更好地节省电池,尽管这是基于cocos2d如何处理暂停导演与暂停场景的猜测。

#1


15  

Pausing SKView stops calling update: method for SKScene.

暂停SKView会停止调用SKScene的update:方法。

Pausing SKScene doesn't do that.

暂停SKScene不会那样做。

I usually pause both SKScene and SKView

我经常暂停SKScene和SKView

EDIT:

As of iOS9 pausing the scene will pause the update: method.

从iOS9暂停场景将暂停更新:方法。

#2


2  

The effect is the same. You still have the paused property on the scene because it's a subclass of SKNode and the scene may need to be paused during transitions, either through the SKView setting that controls whether scenes are paused during transitions or manually.

效果是一样的。您仍然在场景中具有暂停属性,因为它是SKNode的子类,并且在转换期间可能需要暂停场景,可以通过控制场景在转换期间暂停还是手动暂停的SKView设置。

I would wager that pausing the view would also be able to "freeze" a currently running transition, which is about the only thing you can't pause by pausing the scene(s) alone.

我敢打赌暂停视图也能够“冻结”当前正在运行的转换,这是你不能单独暂停场景而暂停的唯一事情。

Therefore pausing the view may also pause all internal timers and draw calls, so a paused view may be better to conserve battery, though that's a guess based on how cocos2d handles a paused director vs paused scene.

因此暂停视图也可能暂停所有内部计时器并绘制呼叫,因此暂停视图可能更好地节省电池,尽管这是基于cocos2d如何处理暂停导演与暂停场景的猜测。