Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 游戏在swift中从后台恢复后退出暂停状态_Ios_Swift_Appdelegate - Fatal编程技术网

Ios 游戏在swift中从后台恢复后退出暂停状态

Ios 游戏在swift中从后台恢复后退出暂停状态,ios,swift,appdelegate,Ios,Swift,Appdelegate,我正在用SpriteKit开发一个游戏,在执行过程中可以暂停,也可以恢复。 但是,当游戏暂停时按下home(主页)按钮时,ApplicationIdentinterBackground出现问题,因为当我恢复游戏时,实体立即开始移动,即使游戏之前已暂停。 我找不到在AppDelegate中实现applicationidentinterbackground和其他相关方法的方法,因为它与我的游戏场景之间没有联系。swift 我实际上是用代码暂停实体 entitiesLayerNode.paused =

我正在用SpriteKit开发一个游戏,在执行过程中可以暂停,也可以恢复。 但是,当游戏暂停时按下home(主页)按钮时,
ApplicationIdentinterBackground
出现问题,因为当我恢复游戏时,实体立即开始移动,即使游戏之前已暂停。 我找不到在
AppDelegate
中实现
applicationidentinterbackground
和其他相关方法的方法,因为它与我的
游戏场景之间没有联系。swift

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

entitiesLayerNode.paused = true
gameState = .GamePaused
编辑:

我想显式暂停
entitiesLayerNode
,因为我还有其他要保留的“移动”节点。问题在于,根据下面给出的建议,该方法会暂停所有操作!我只需要暂停这一层。 我认为问题在于我无法从视图控制器访问
entitiesLayerNode
。 我通常使用这个片段

let mainScene = scene as GameScene
mainScene.entitiesLayerNode.pause = true
但是Xcode给了我一个错误,
场景
是一个未解析的标识符。

AppDelegate:

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

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
    }
}

如果我暂停所有场景,这是可行的,但由于我有几个节点,我只想暂停entitiesLayerNode,而这段代码似乎不起作用。此外,我无法从viewDidLoad访问skView,我必须根据您发送的链接更改PauseGamese()。设置所有必要的IBOutlet是您的责任。我给了你一个大致的指导,你应该自己根据自己的需要修改代码。我不知道这个接口是通过编程编写的。我的viewDidLoad中有一个skView,但我不知道为什么我不能在PauseGamese中访问它…由于这篇文章,我暂时解决了这个问题:在我的场景self.view的更新方法中添加以下行。paused=true