触摸节点时,我有以下代码从主菜单场景移动到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
我不确定如何更正此错误...
答案 0 :(得分:0)
尝试以下方法:
let nextScene = SKScene(fileNamed: "GameScene")