【发布时间】:2015-02-21 14:20:21
【问题描述】:
我有一个 SKShapeNode 并为它设置了一个名称,但是当我尝试在 touch 中检测到它时,它的工作方式与您与其他 sprite 一起使用的方式不同。
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if let body = self.nodeAtPoint(location) as? SKSpriteNode {
if var name: String = body.name {
switch name {
case "myShape":
println("Shape Touched")
case "enemy":
println("Enemy Touched")
default:
}
}
}
}
}
enemy 是一个 SKSpriteNode,它被正确检测到,但形状是 SKShapeNode 却没有。我正确输入了字符串名称。
【问题讨论】:
标签: sprite-kit touch skshapenode