我只是想让用户在屏幕上拖放某些精灵。我看到的答案是检查精灵的名称(如下所示)。必须有更好的方法来做到这一点。感谢您的任何意见。
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
var nodeTouched = SKNode()
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
nodeTouched = self.nodeAtPoint(location)
if(nodeTouched.name? == "character") {
character.position=location
currentNodeTouched = nodeTouched
} else {
currentNodeTouched.name = ""
}
}
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
var nodeTouched = SKNode()
nodeTouched = self.nodeAtPoint(location)
if(currentNodeTouched.name == "character") {
character.position = location
}
}
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
var nodeTouched = SKNode()
nodeTouched = self.nodeAtPoint(location)
if(currentNodeTouched.name == "character") {
character.position = location
}
}
}