Search code examples
touchlivecodeswipe-gesture

Disabling touchEnd when pressing buttons


I have a game which is controlled through swipe gestures. Each turn, the user swipes and it moves pieces on the screen.

My problem is, when pressing the "Start" button, the game starts and sometimes records the first swipe gesture at the same time.

How do I disable the touch messages when I am pressing a button?


Solution

  • You can add a touchEnd handler to the Start button:

    on touchEnd
    end touchEnd
    

    As long as you don't have a pass touchEnd command in this handler, the touchEnd handler higher up de message hierarchy won't run.

    Another possibility is to check for the target higher up the message hierarchy:

    on touchEnd
      if the short name of the target is "Start" then
        exit touchEnd
      else
        // remainder of your script
      end if
    end touchEnd