0

I have a Color Sprite object which can move and bounce at the wall. How can I make it disappear when I catch it and touch it on the screen?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Feindpak
  • 45
  • 1
  • 6

1 Answers1

2

you have to set a name for your sprite like "ballNode", then in "touchesBegan" function you can handle it.

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    for touch in (touches) {
        let positionInScene = touch.location(in: self)
        let touchedNode = self.atPoint(positionInScene)
        if let name = touchedNode.name {
            if name == "ballNode" {
                //make it hidden by touchedNode.isHidden = true
                //or remove it from parent by touchedNode.removeFromParent()
            }
        }
    }
}
Mina
  • 2,167
  • 2
  • 25
  • 32