ユーザーに特定のスプライトを画面上でドラッグアンドドロップさせようとしています。これについて私が見た答えは、スプライトの名前をチェックすることです(以下のようなもの)。これを行うためのより良い方法があるはずです。ご意見ありがとうございます。
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
}
}
}