Diego Esc Diego Esc - 10 months ago 68
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 Source

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