TAP - DOUBLE TAP - FLICK - PRESS/HOLD

Good day, to all!

I have read that single taps, double taps, and flicking in a given direction are quite easily implemented.

The tap and double tap are very straight forward in my head, as Corona seems to have made this easy on us.

The flick, obviously has a bit more math on our part.

And pressing and HOLDING a button for, say 2 seconds can easily be coded as well.

I would like to play around with a rectangle on the screen, representing a card, for a card game.

  1. If that card is flicked UP, I would like a certain function to fire.

  2. If that card is flicked to the LEFT, I would like a certain function to fire.

  3. If that card is flicked to the RIGHT, I would like a certain function to fire.

  4. If that card is flicked to the DOWN, I would like a certain function to fire.

  5. If that card is pressed and held for two seconds, I would like a certain function to fire.

I can manage the single tap and double taps. As a double tap is merely using TIME to determine the taps in succession; and I assume the PRESS AND HOLD is similar.

Is it possible for someone to show me the code for the above 5 conditions?

If this is asking too much I do apologize, for not knowing the involvement. 

Sooner or later, I will know what I have just asked of this community! :slight_smile:

PEACE

Thanks in advance

Chris:)

I think Rob has posted code for a swipe detection function, so you should do a search. I’ve implemented a press-and-hold detection with a touch listener, and it’s not too painful, but for IP reasons can’t post it here. My advice is to keep this in a module if you can.

Hi Chris,

Implementing “flick” isn’t difficult. Basically, when handling a touch, you can read these event properties:

http://docs.coronalabs.com/api/event/touch/index.html

When you think of the mechanics behind a flick, it’s basically a touch down with a short drag motion over a short time span. And so basically you want to do this for a LEFT flick:

  1. Detect the TIME when the touch began (event.time during event.phase==“began”). Save this to a variable like “startTime”.

  2. Get the DISTANCE from the start point to the end point (event.x-event.xStart on event.phase==“ended”). This will be negative for flicking left.

  3. Also get the DURATION of the touch when it ends (system.getTimer()-startTime during event.phase==“ended”).

  4. If the DURATION is short enough (i.e. < 300 milliseconds) and the DISTANCE is long enough, then you’ve got a left flick.

And you can mimic this for the other directions easily enough.

Hope this helps,

Brent

I think Rob has posted code for a swipe detection function, so you should do a search. I’ve implemented a press-and-hold detection with a touch listener, and it’s not too painful, but for IP reasons can’t post it here. My advice is to keep this in a module if you can.

Hi Chris,

Implementing “flick” isn’t difficult. Basically, when handling a touch, you can read these event properties:

http://docs.coronalabs.com/api/event/touch/index.html

When you think of the mechanics behind a flick, it’s basically a touch down with a short drag motion over a short time span. And so basically you want to do this for a LEFT flick:

  1. Detect the TIME when the touch began (event.time during event.phase==“began”). Save this to a variable like “startTime”.

  2. Get the DISTANCE from the start point to the end point (event.x-event.xStart on event.phase==“ended”). This will be negative for flicking left.

  3. Also get the DURATION of the touch when it ends (system.getTimer()-startTime during event.phase==“ended”).

  4. If the DURATION is short enough (i.e. < 300 milliseconds) and the DISTANCE is long enough, then you’ve got a left flick.

And you can mimic this for the other directions easily enough.

Hope this helps,

Brent