当应用程序变为活动状态时,如何保持SpriteKit场景暂停? [英] How to keep SpriteKit scene paused when app becomes active?

查看:156
本文介绍了当应用程序变为活动状态时,如何保持SpriteKit场景暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有阻止SpriteKit在进入前景/变为活动时自动取消暂停场景?

Is there anyway to prevent SpriteKit from automatically unpausing a scene when entering foreground/becoming active?

我设置暂停=真并希望即使应用程序在被发送到后台后再次变为活动状态也能保持这种状态。

I set paused = true and want it to remain so even when the app becomes active again after having been sent to the background.

我应该补充说我正在这样做虽然我不希望这方面的行为有所不同。

I should add that I'm doing this in swift, though I would not have expected the behaviour to be different in this regard.

推荐答案

不确定它是否相同目标C,但在swift中我不得不覆盖SKView在幕后调用的回调函数,

Not sure if it is the same in objective C, but in swift I had to "override" a callback function that SKView calls behind the scenes,

func CBApplicationDidBecomeActive()
{

}

此功能导致暂停重置。

(请注意不应用覆盖关键字)

(note override keyword should not be applied)

在某些情况下,您只想保留暂停状态,改为创建一个新变量并覆盖isPaused方法。

In some cases where you want to just retain the state of pause, make a new variable instead and override the isPaused method.

class GameScene:SKScene
{
  var realPaused = false
  {
     didSet
     {
         isPaused = realPaused
     }
  }
  override var isPaused : Bool
  {
    get
    {
       return realPaused
    }
    set
    {
      //we do not want to use newValue because it is being set without our knowledge
      paused = realPaused
    }
  }
}

这篇关于当应用程序变为活动状态时,如何保持SpriteKit场景暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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