【发布时间】:2019-05-15 13:37:11
【问题描述】:
我正在编写的代码存在一个问题,即每当我点击节点以外的某个地方(例如背景)时,应用程序最终都会崩溃。
我尝试过创建一个 if let 语句,但它说我不能将 SKnode 向下转换为更可选的类型 SKSpriteNode。
我也试过if node.contains(position of touch)。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let touchLocation = touch?.location(in: self) {
let selectedNode = nodes(at: touchLocation)[0] as! SKSpriteNode
activeObject = selectedNode
storedData = Array(activeObject.name!)
let platformStoredInt = storedData[2]
storedPlatform = Int(platformStoredInt.unicodeScalars.first!.value - Unicode.Scalar("0")!.value)
}
}
点击除被视为对象的 SKSpriteNode 之外的任何内容都会导致 SIGABRT。
【问题讨论】:
标签: swift xcode sprite-kit