0
我只是想讓用戶在屏幕上拖放某些精靈。我看到的答案是檢查精靈的名稱(如下所示)。必須有更好的方法來做到這一點。感謝您的任何意見。使用swift拖放不使用硬編碼名稱的精靈
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
}
}
}