【问题标题】:pause game when WillResignActiveWillResignActive 时暂停游戏
【发布时间】:2015-03-19 21:22:00
【问题描述】:

我有一些带有 SKAction() 的精灵节点; 它们是名为 world 的 sknode 的子节点

如果我在游戏中按下暂停按钮,它的 spirenodes 动画

func pause(){
    if(isGamePaused)
        isGamePaused = false;
        world.paused = false;
    } else {
        isGamePaused = true;
        world.paused = true;
    }
}

但在后台运行时我无法暂停游戏

 NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("goBG:"), name: UIApplicationWillResignActiveNotification, object: nil);

func goBG(sender: AnyObject){
    self.isGamePaused = true;
    self.world.paused = true;

    println("bg"); // called
    println(world.paused);// return true
}

【问题讨论】:

  • SpriteKit 会在您的应用移至后台时自动暂停,并在应用处于活动状态时恢复。

标签: ios8 sprite-kit skspritenode skaction


【解决方案1】:

您可以添加尝试观察UIApplicationDidEnterBackgroundNotification 而不是UIApplicationWillResignActiveNotification 通知,或者您可以在您的AppDelegate 方法applicationDidEnterBackground 中调用一个函数来暂停游戏。

【讨论】:

  • 你能举个例子吗?
  • UIApplicationDidEnterBackgroundNotification - 不要暂停 SKAction
【解决方案2】:

如果有人仍然感兴趣。这里有解决这个问题的方法:

SpriteKit Autoresumes and auto pauses iOS8

【讨论】:

    猜你喜欢
    • 2016-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 2014-07-14
    相关资源
    最近更新 更多