触摸节点的Swift访问方法

时间:2014-10-12 00:34:17

标签: ios xcode swift sprite-kit

使用以下方法拖动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 个答案:

答案 0 :(得分:1)

您可以使用以下语法:

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