-5

enter image description hereI am coding a pong game and i want to add a button to a sprite kit game that can change a value between 1 - 0.01.

I would like the add a button to do this function. If anyone could tell me how to do this it would be greatly appreciated.

I am sorry for being a noob. I'm a student.

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    let touchLocation = touch!.location(in: self)
    // Check if the location of the touch is within the button's bounds
    if button.contains3 {
         print("tapped!")
    }
}

Thank You

Mike JS Choi
  • 1,081
  • 9
  • 19
Derppey
  • 23
  • 4

1 Answers1

3

every touches in spritekit is handle by SpriteNodes. so if you need a button to be clicked and do something you have to add a spriteNode on the scene and in touches began method handle the touch event. there is a complete answer for your question in this thread

Community
  • 1
  • 1
Mina
  • 2,167
  • 2
  • 25
  • 32