0

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 :)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
CoolMAn
  • 1,851
  • 2
  • 12
  • 23

1 Answers1

0

Swift Spritekit Adding Button Programaticly

This Link posted by Gavidi Harikrishna answered my question completely. I hope it also reaches who ever seeks the same answer

Community
  • 1
  • 1
CoolMAn
  • 1,851
  • 2
  • 12
  • 23