使用以下方法拖动SKSpriteNode
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch in touches {
let location = touch.locationInNode(self)
var touchedNode = nodeAtPoint(location)
if touchedNode.isKindOfClass(Card) {
touchedNode.position = location
}
}
}
if语句确认它; s pif是一个特定的类,我现在如何调用方法并访问该节点的属性?
答案 0 :(得分:1)
您可以使用以下语法:
if let cardNode = touchedNode as Card {
cardNode.position = location
// cardNode is of type card. You can access all its
// methods and properties
}