Assistance scripting this touch listener.

I need a touch listener that behaves like so:

  1. When touching the screen and not moving, a variable is set to “on”. DONE.

  2. When not touching the screen, that variable is set to “off”. DONE

  3. if the player moves their finger, that variable is set to “moving”. It stays as “moving” until the player is no longer moving their finger around the screen OR a timer reaches its end(havent decided yet), at which point the variable will return to “on” until/unless the player ends the touch.

The problem is that the moved phase will stay the active phase until the touch is ended, even if the player is no longer moving their finger. is there a way to revert it to the “on” phase if certain conditions are met?

I wont be at my computer for a few hours but i wanted to get the question out because it would be nice to get home and implement it immediately, or at least have a starting point since my current attempts have been met with crazy bugs. :stuck_out_tongue:

Thanks for any answers. Hope this was clear. 

Corona events don’t continuously generate. You will only get a “moved” phase is the finger actually moved. What you might want to do is start a timer when you get a move event for however long you want to determine “stopped” is and then change your state to on. But what happens if you determined they stopped and then they resume?

local stopTimer local state = "off" local function handleTouch( event )      if event.phase == "began" then           state = "on"      elseif event.phase == "moved" then          if stopTimer then              timer.cancel( stopTimer )          end          stopTimer = timer.performWithDelay( 500, function() state = "on"; end)          state = "moving"      else          state = "off"      end end

or some such!

Rob

[quote name=“Rob Miracle” post=“306672” timestamp=“1442785951”]Corona events don’t continuously generate. You will only get a “moved” phase is the finger actually moved. What you might want to do is start a timer when you get a move event for however long you want to determine “stopped” is and then change your state to on. But what happens if you determined they stopped and then they resume? Rob[/quote] If they stop and resume I would like it to switch back to moving. What about the event.x/y properties? Are they continuously updated to reflect the current touch position? Hopefully If so it would be applicable to compare the values over time, would it not? I could then alter the state var according to the results of the comparison. Not having computer access ATM drives me crazy. Asking questions about what I’m going to be working on when I get back make me feel like I’m still getting stuff done.

Corona events don’t continuously generate. You will only get a “moved” phase is the finger actually moved. What you might want to do is start a timer when you get a move event for however long you want to determine “stopped” is and then change your state to on. But what happens if you determined they stopped and then they resume?

local stopTimer local state = "off" local function handleTouch( event )      if event.phase == "began" then           state = "on"      elseif event.phase == "moved" then          if stopTimer then              timer.cancel( stopTimer )          end          stopTimer = timer.performWithDelay( 500, function() state = "on"; end)          state = "moving"      else          state = "off"      end end

or some such!

Rob

[quote name=“Rob Miracle” post=“306672” timestamp=“1442785951”]Corona events don’t continuously generate. You will only get a “moved” phase is the finger actually moved. What you might want to do is start a timer when you get a move event for however long you want to determine “stopped” is and then change your state to on. But what happens if you determined they stopped and then they resume? Rob[/quote] If they stop and resume I would like it to switch back to moving. What about the event.x/y properties? Are they continuously updated to reflect the current touch position? Hopefully If so it would be applicable to compare the values over time, would it not? I could then alter the state var according to the results of the comparison. Not having computer access ATM drives me crazy. Asking questions about what I’m going to be working on when I get back make me feel like I’m still getting stuff done.