2014-10-12 52 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 
    }