此代码位于viewDidLoad函数中。第一次调用就可以了。但是,然后我从同一情节提要文件中在其顶部显示一个subView,当'let skView = gameView as!再次调用SKView,并引发致命错误:发现nil ...如何停止其他时间调用它?我想不到的是我能做的任何检查。

if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.

        let skView = gameView as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .AspectFill

        skView.presentScene(scene)

    }

最佳答案

override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        let skView = self.view as! SKView
        if skView.scene == nil {
            if let scene = GameScene(fileNamed:"GameScene") {
                skView.presentScene(scene)
            }
        }
}

关于ios - (Swift SpriteKit)仅允许SKScene演示一次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38042928/

10-12 05:57