当我在某些设备上重置场景时,我的新场景似乎被前一场景的屏幕截图覆盖。这不会发生在我的iPhone 6 Plus(iOS 8.1.1)或任何模拟器中。我通过将视图控制器的视图从SKView更改为带有SKView子视图的UIView,在我的iPhone 5(iOS 7.1.2)上解决了这个问题。显然在iOS 7上,在故事板中向SKView添加按钮是个问题,但问题仍然存在于iPad上。
在我的iPad 2(8.1.1)上,问题只发生在我的第二次播放之后。游戏第一次运行,当你再次播放时它再次起作用,然后如果你第三次点击播放你得到这个节点的物理体的幽灵仍然存在(showPhysics设置为true,如果设置为false,则屏幕是空白的白色):
奇怪的是,我仍然可以玩游戏,我只是看不到这个静态屏幕截图下面发生了什么。我听到我的播放器弹跳并碰到敌人,但屏幕保持静止。
根据日志,前一个场景正在被取消。
以下是从开始到重置的流程的相关部分:
// MainMenuVC
@IBAction func startGamePressed(sender: UIButton) {
let gameViewController = self.storyboard!.instantiateViewControllerWithIdentifier("GameViewController") as GameViewController
navigationController!.pushViewController(gameViewController, animated: false)
}
// GameViewController
override func viewDidLoad() {
super.viewDidLoad()
playGame()
}
func playGame() {
let skView = self.view as SKView
let scene = GameScene(size:CGSize(width: 640, height: 1136))
scene.scaleMode = .AspectFill
skView.ignoresSiblingOrder = true
weak var weakSelf = self
scene.moveToGameOverScreen = { // Calls up to VC to present GameOverVC modally
let vc = weakSelf!.storyboard!.instantiateViewControllerWithIdentifier("GameOverVC") as GameOverVC
vc.gameOverDelegate = weakSelf
vc.modalTransitionStyle = .CrossDissolve
weakSelf!.navigationController!.presentViewController(vc, animated: true, completion: nil)
}
skView.presentScene(scene)
}
// GameScene
func lose() {
if (self.moveToGameOverScreen != nil) {
self.moveToGameOverScreen!() // Calls up to VC to show GameOverVC modally
}
}
// GameOverVC
@IBAction func play(sender: UIButton) {
dismissViewControllerAnimated(false, completion: nil) // To dismiss this modal
gameOverDelegate?.playGame() // resets
}