2016-03-22 6 views
4

私のゲームがバックグラウンドモードに入ると、ゲームを完全に一時停止したいと思います。アプリケーションが背景に入っているときにSceneKitシーンを中断する

AppDelegateで:現時点では、これは私が何をすべきかである私のゲームコントローラで

func applicationWillResignActive(application: UIApplication) { 
    gameViewControllerDelegate?.pauseGame() 
} 

func pauseGame() { 
    buttonPausePressed(buttonPausePlay) 
} 

func buttonPausePressed(sender: UIButton!) { 
    scnView?.scene?.paused = true 
    stopMusic() 
    let exampleImage = UIImage(named: "16-play")?.imageWithRenderingMode(.AlwaysTemplate) 
    sender.setImage(exampleImage, forState: UIControlState.Normal) 
} 

メソッドが呼び出されると、ボタンの画像が変更されます。ゲームさえも中断されます。しかし、私は再びアプリを開いて、使用していないが、一時停止したとき:

scnView?.scene?.paused = false 

すべてのグラフィックスの変更やその他の奇妙なことが起こります。 SCNActionsが一時停止されていないようです。何か案は?

答えて

3

私は同じ問題を抱えていました。あなたのAppDelegate.swift

func applicationWillResignActive(application: UIApplication) 
{ 
    let viewControllers = self.window?.rootViewController?.childViewControllers 
     for vc in viewControllers! 
     { 
      if vc.isKindOfClass(GameViewController) 
      { 
       let view = vc as! GameViewController 
       view.comesFromBackground() 
      } 
     } 
    } 

でそして、あなたのGameViewControllerに:

func comesFromBackground() 
{ 
    let skView: SKView = self.view as! SKView 
    let scene = skView.scene as! GameScene 
    scene.comesFromBackground = true 
} 

最後に、あなたのGameSceneに:

override func update(currentTime: CFTimeInterval) 
{ 
    if comesFromBackground{ 
     comesFromBackground = false 
     gameViewController.pauseScene() 
    } 
} 

変数comesFromBackgroundはbooleanです。 目的は、再度あなたがあなたのgameSceneでブール値を設定し、再びあなたがゲームを停止するアプリケーションを開くときです。

この度はお手数ですが

関連する問題