Diego Esc Diego Esc - 17 days ago 5
Swift Question

Add nodes where touches began

I´m making a game with Swift.
I need to add nodes where I press the screen, I know this is not from other planet but I can't do it.

Answer

Highly simplified example could look like this:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard let touch = touches.first else { return }
    let location = touch.location(in: self)
    let node = SKNode()
    node.position = location
    addChild(node)
}
Comments