sprite-kit

Detecting touch input on iOS devices

Detecting touch

You can override 4 methods of SKScene to detect user touch

class GameScene: SKScene {
    

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    }
    
    override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
    }
    
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
    }
    
    override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
    
    }
}

Please note that each method receives a touches parameter which (under particular circumstances) can contain more then one single touch event.


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow