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?
Asked
Active
Viewed 268 times
0
-
2Tutorial, that might help: https://www.raywenderlich.com/145318/spritekit-swift-3-tutorial-beginners – shallowThought Dec 03 '16 at 21:13
1 Answers
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