Search Unity

handling ending touch ended events that span multiple frames

Discussion in 'iOS and tvOS' started by Dom, Feb 6, 2010.

  1. Dom

    Dom

    Joined:
    Jul 10, 2007
    Posts:
    91
    Hi there,

    I saw that i.e. touch ending events may be available across multiple frames.

    I have the scenario where the user goes from one menu to another via buttons. A new button on the same spot as the one that got triggered from the previous menu might be fired off from the same touch release event.

    How do you deal with that? Custom touchInput-manager/wrapper that holds flags for consumed release events?
     
  2. MikaMobile

    MikaMobile

    Joined:
    Jan 29, 2009
    Posts:
    845
    I think your proposed work-around is probably the way to go. The way I've handled it is with something like this...

    Code (csharp):
    1.  
    2. if (iPhoneInput.TouchCount == 0) {
    3.        touchReleased = true;
    4. }
    5.  
    ... where touchReleased is set to "false" whenever a touch is detected on one of my UI elements. It remains "false" until no touches are detected, so including " touchReleased" in the condition for any of your UI input detection would prevent a misfire from a held touch.

    I actually got in the habit of using variables to keep track of touch states manually before learning about the whole touch phase thing (and that its slightly unreliable). So I just keep using variables as middlemen to this day, it seems to work more cleanly.