我正在尝试在GameViewController中运行GameScene函数,并且收到上面提到的错误。以下是代码的基础知识:
这在GameScene中调用:
func resetPosition(){
someNode!.position = otherPosition! //this is the line with the error - otherPosition IS called previously as a CGPoint
}
在GameViewController中:
let gameScene = GameScene.self()
func reset(){ // reset is called by a UIButton
gameScene.resetPosition()
}
模拟器打开并运行正常,但是一旦按下链接到重置的按钮,应用程序就会崩溃。如果您需要更多代码,我很乐意提供。
答案 0 :(得分:0)
听起来好像someNode
或otherPosition
都是零。你说早先调用了otherPosition
,所以它必须是someNode
。
如果您在更新位置之前尝试解包someNode
会怎样?
if let someNode = someNode {
someNode.position = otherPosition
} else {
print("someNode was nil")
}