gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 01:42:58 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com