ios - 游戏在快速从后台恢复后退出暂停状态

标签 ios swift appdelegate

我正在使用 SpriteKit 开发一款游戏,该游戏可以在执行期间暂停并可以恢复。 但是当游戏暂停时按下主页按钮时,我遇到了 applicationDidEnterBackground 问题,因为当我恢复游戏时,即使游戏之前已暂停,实体也会立即开始移动。 我找不到在 AppDelegate 中实现 applicationDidEnterBackground 和其他相关方法的方法,因为它和我的 GameScene.swift

之间没有任何联系>

我实际上是用代码暂停实体

entitiesLayerNode.paused = true
gameState = .GamePaused

编辑:

我想显式暂停 entitiesLayerNode 因为我想保留其他“移动”节点。问题是,按照下面给出的建议,该方法会暂停一切!我只需要暂停该层。 我认为问题是我无法从 View Controller 访问 entitiesLayerNode 。 我通常使用代码片段

let mainScene = scene as GameScene
mainScene.entitiesLayerNode.pause = true

但是 Xcode 给我一个错误,指出 scene 是一个无法解析的标识符。

最佳答案

here 几乎相同

应用程序委托(delegate):

func applicationWillResignActive(application: UIApplication) {
    NSNotificationCenter.defaultCenter().postNotificationName("PauseGameScene", object: self)
}

游戏场景 View Controller :

override func viewDidLoad() {
    super.viewDidLoad()

    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("pauseGameScene"), name: "PauseGameScene", object: nil)
}

func pauseGameScene() {
    if self.skView.scene != nil {
        self.skView.paused = self.skView.scene.paused = true
    }
}

关于ios - 游戏在快速从后台恢复后退出暂停状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27655162/

相关文章:

ios - Swift 2.1 iOS 启动时结构中的静态 bool 值设置为错误值

ios - Flutter:应用程序的 Info.plist 不包含 CFBundleVersion

ios - 如何在 swift 4 IOS 中从 TableViewController 的 "viewForHeaderInSection"方法设置 UITableViewHeaderFooterView 的属性?

arrays - 在 Swift 中,我如何交错 NSMutableParagraphStyle() 和 NSMutableAttributedString 来格式化要在 UITextView 中显示的字符串?

ios - SpriteKit : A Lot of sprites (1000+) with Bit Blitting

ios - 我的键盘不会切换 : neither endEditing nor resignFirstResponder works

ios - 本地化 XCode 4.5 + 在主 UIWebView/IOS 中加载特定语言的 PDF

ios - 如果文本不适合框架,如何向 UILabel 添加点

iOS 委托(delegate)方法未调用