Search code examples
xcodeswifttouchesbegan

How to end the touchesBegan function in swift spritekit


I am building a game in swift spriteKit, I am working with a TouchesBegan function and a DidBeginContact function, when the DidBeginContact function is called I want the TouchesBegan function to be inactive. I searched for tutorials on how to accomplish this but to no avail.. Some help would be legit.


Solution

  • I dont think there is a way to turn it off by default.

    Just create a bool

    var touchesAllowed = true
    

    Than in your didBeginContact method you set it to false

    touchesAllowed = false
    

    and set it to true whenever you want touches allowed again

    touchesAllowed = true
    

    Finally in your touches method right at the beginning you check for it

    guard touchesAllowed else { return }
    /// rest of your touch code