Kyle Goslan
Kyle Goslan

Reputation: 10940

Swift access methods of touched Node

Im dragging a SKSpriteNode around with the following method

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
        }

    }
}

the if statement is confirming that it;s pif a specific class, how can I now call methods and access properties this node?

Upvotes: 0

Views: 461

Answers (1)

Anthony Kong
Anthony Kong

Reputation: 40874

You can use this syntax:

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

Upvotes: 1

Related Questions