游戏从后台快速恢复后退出暂停状态
我正在开发一个SpriteKit游戏,可以在执行过程中暂停,可以继续。 但是当游戏暂停时按下homebutton时,我遇到了applicationDidEnterBackground
的问题,因为当我恢复游戏时,即使游戏之前暂停,实体也会立即开始移动。 我找不到在AppDelegate
实现applicationDidEnterBackground
和其他相关方法的方法,因为它和我的GameScene.swift
之间没有连接
我实际上是用代码暂停实体
entitiesLayerNode.paused = true gameState = .GamePaused
编辑:
我想明确地暂停entitiesLayerNode
因为我有其他'移动'节点,我想保留。 问题是,在下面给出的build议,方法暂停一切! 我只需要暂停该图层。 我认为这个问题是我无法从视图控制器访问entitiesLayerNode
。 我通常使用片段
let mainScene = scene as GameScene mainScene.entitiesLayerNode.pause = true
但Xcode给了我一个错误,那个scene
是一个无法parsing的标识符。
几乎和这里一样
AppDelegate中:
func applicationWillResignActive(application: UIApplication) { NSNotificationCenter.defaultCenter().postNotificationName("PauseGameScene", object: self) }
GameSceneViewController:
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 } }