2014-10-12 28 views
0

林拖着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特定類,我怎麼能現在調用方法和訪問屬性這個節點?

回答

1

你可以使用這個語法:

if let cardNode = touchedNode as Card { 
     cardNode.position = location 
     // cardNode is of type card. You can access all its 
     //  methods and properties 
    }