檢測觸控

你可以覆蓋 SKScene 的 4 種方法來檢測使用者觸控

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?) {
    
    }
}

請注意,每個方法都會收到一個 touches 引數,該引數在特定情況下可以包含多個單個觸控事件。