I am currently developing a game using swift with xCode and I'm not quite sure how to make a button "pressable". I usually do something like this:
var button = SKSpriteNode(imageNamed:"sample")
button.xScale = 1
button.yScale = 1
button.name = "pressHere"
and then in the touchesBegan function I do this:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
var touch: UITouch = touches.anyObject() as UITouch
var location = touch.locationInNode(self)
var node = self.nodeAtPoint(location)
if (node.name == "pressHere") {
//whatever I want the button to do
}
}
I've found that if I do this method a lot my game will crash. Perhaps this isn't really what causes the issue, but it's always helpful learning a new way :)