我的暂停系统可以在游戏内部完美运行,并且当应用程序移至后台然后再次激活时,游戏会保持暂停状态,但我现在的问题是当它激活时,我的暂停屏幕不显示。
应用委托:
func applicationDidBecomeActive(application: UIApplication) {
NSNotificationCenter.defaultCenter().postNotificationName("Pause", object: nil)
}
视图控制器:
override func viewDidLoad() {
super.viewDidLoad()
let scene = GameScene()
// Configure the view.
let skView = self.view as! MainView
NSNotificationCenter.defaultCenter().addObserver(skView, selector: "setStayPaused", name: "Pause", object: nil)
skView.ignoresSiblingOrder = true
scene.scaleMode = .AspectFill
scene.size = skView.bounds.size
skView.presentScene(scene)
}
MainView(我的自定义 skView):
class MainView: SKView {
var stayPaused = false as Bool
override var paused: Bool {
get {
return super.paused
}
set {
if (!stayPaused) {
super.paused = newValue
}
stayPaused = false
}
}
func setStayPaused() {
if (super.paused) {
self.stayPaused = true
}
}
}
游戏场景:
override func didMoveToView(view: SKView) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "pauseGame", name: "Pause", object: nil)
}
func pauseGame() {
if isFirstTime == false { // to make sure that the app did not just get launched
pauseScreen.hidden = false // doesn't show
pauseButton.hidden = false // doesn't show
view?.paused = true
scene?.paused = true
}
}