swift sprite kit在场景之间移动

时间:2018-01-10 16:39:13

标签: swift syntax sprite-kit

触摸节点时,我有以下代码从主菜单场景移动到GameScene(设置为按钮)

我每次都不断崩溃,不知道是什么导致了崩溃。

if node.name == "level1Button"
        {   level1Button.texture = SKTexture(imageNamed: "square")
            level2Button.texture = SKTexture(imageNamed: "square3")
            print ("level1button")
           // self.view?.presentScene(scene)

            let transition = SKTransition.fade(withDuration: 1.0)

            let nextScene = GameScene(size: scene!.size)
            nextScene.scaleMode = .aspectFill //set the scale mode like you did in your view controller

            scene?.view?.presentScene(nextScene, transition: transition)

        }

在这一行我得到了

nextScene.scaleMode = .aspectFill //set the scale mode like you did in your view controller

//Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

我不确定如何更正此错误...

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

let nextScene = SKScene(fileNamed: "GameScene")