Working Double Tap detection in Corona?

Does anyone have working code to detect single and double taps on Corona?

I set the tap delay to 2 seconds tops

system.setTapDelay( 2 )  

Here is the event listener function which always goes to Help1_scene

local function HelpTapEvent(event)     if (event.numTaps \> 1 ) then         storyboard.gotoScene( "Help2\_scene", "flip", \_G.slideTrans  )     else         storyboard.gotoScene( "Help1\_scene", "flip", \_G.slideTrans  )       end     return(true) end  

Here is the code that puts up a question mark image and if they need help, it would jump to the help file scene.

    helpButton = display.newImageRect("questionmark.png",45,45)     helpButton.x = \_G.nextButtonX     helpButton.y = \_G.nextButtonY     helpButton.alpha = \_G.nextButtonAlpha     screenGroup:insert( helpButton )  

I want to overload the question mark with a double tap to allow it to go to the stats page if they double tap the question mark. So far I can only get it to go to Help. 

Thanks!
Stu

Hi Stu,

This could be a bit tricky, because you’re trying to tell the system to “ignore” the single tap “just in case” a double-tap is registered… and if so, process the double-tap action. About all I can think of is setting a timer (of no more than your tapDelay time) on the first tap, then waiting to see if another tap is registered in that timespan. If so, you go to the double-tap point, and if not, you use the single-tap result. But, that may seem a bit awkward for people who do a single tap, since there will be a delay before anything happens (and if they’re impatient, they might tap again, thinking that the first tap wasn’t registered… and then they’ll get the double-tap event, which isn’t what they intended).

Food for thought… you might just need to rethink how you implement this. :wink:

Take care,

Brent

So what you’re saying is Corona does not do double taps and single taps? It is fairly simple to implement. It does require single taps to wait past the double tap threshold before registering either a second tap or the single tap.

what is the setTapDelay for? it does not seem to be implemented, since the taps are immediately registered regardless of what it is set for. Is the documentation correct that the numeric value is seconds and not ms?

Thanks!
stu

Hi Stu,

To clarify, what I meant was that Corona does detect the number of taps (using the “event.numTaps”) property. But, the assumption is that a particular button or object is supposed to wait for the number of taps you specify, using the conditional logic. So, when you tap on an object, you’ll get a tap response… whether you process this is up to you. If you want to sense a double tap, you can “wait” for the second tap to occur, and then handle that condition as needed. But, I don’t believe there’s a way to detect both a single and double tap on one object unless you wait for 1-2 seconds (the max duration which you’ll allow a double tap), and then process the number of taps that occurred, either 1 or 2, and take the necessary action. But then, it goes back to what I said how an impatient user will likely tap the button again, thinking that the tap didn’t trigger, and they’ll get a double tap when they meant a single. :slight_smile:

Brent

I tried the tap delay set to all sorts of values and could not detect any change in tap duration. Either I was doing it wrong (always a possibility) or it’s broken…

I assume it is a global value for all tap listeners??

Stu

Hi Stu,

Apologies on this… I just did some more testing, and it appears that the system automatically “waits” for the duration of time you set with “system.setTapDelay()”, and when that duration is up, it reports back how many taps were done in that time… BUT to a maximum of 2 taps. I tried setting the delay to 2 (seconds), which is correct by the way (it’s not supposed to be 2000 as in milliseconds, like with timers). When I tapped on the object multiple times, the max number of hits returned was 2, not like 5.

So, it seems like you can set the delay higher, and Corona will wait for that duration and report back the number of hits within that span… no need to use your own timer or anything. With the delay set to 2 seconds, it ignores the first tap (meaning, it won’t trigger an instant response), but when 2 seconds are up, it reports back the total number.

I would suggest that you test this on whatever devices you have, to ensure it’s working properly at the device level on those devices.

Also, as a side note, I would say that 2 seconds is a bit too high for an actual double tap. 1 second at most, I would suggest. :slight_smile:

Brent

Hi Stu,

This could be a bit tricky, because you’re trying to tell the system to “ignore” the single tap “just in case” a double-tap is registered… and if so, process the double-tap action. About all I can think of is setting a timer (of no more than your tapDelay time) on the first tap, then waiting to see if another tap is registered in that timespan. If so, you go to the double-tap point, and if not, you use the single-tap result. But, that may seem a bit awkward for people who do a single tap, since there will be a delay before anything happens (and if they’re impatient, they might tap again, thinking that the first tap wasn’t registered… and then they’ll get the double-tap event, which isn’t what they intended).

Food for thought… you might just need to rethink how you implement this. :wink:

Take care,

Brent

So what you’re saying is Corona does not do double taps and single taps? It is fairly simple to implement. It does require single taps to wait past the double tap threshold before registering either a second tap or the single tap.

what is the setTapDelay for? it does not seem to be implemented, since the taps are immediately registered regardless of what it is set for. Is the documentation correct that the numeric value is seconds and not ms?

Thanks!
stu

Hi Stu,

To clarify, what I meant was that Corona does detect the number of taps (using the “event.numTaps”) property. But, the assumption is that a particular button or object is supposed to wait for the number of taps you specify, using the conditional logic. So, when you tap on an object, you’ll get a tap response… whether you process this is up to you. If you want to sense a double tap, you can “wait” for the second tap to occur, and then handle that condition as needed. But, I don’t believe there’s a way to detect both a single and double tap on one object unless you wait for 1-2 seconds (the max duration which you’ll allow a double tap), and then process the number of taps that occurred, either 1 or 2, and take the necessary action. But then, it goes back to what I said how an impatient user will likely tap the button again, thinking that the tap didn’t trigger, and they’ll get a double tap when they meant a single. :slight_smile:

Brent

I tried the tap delay set to all sorts of values and could not detect any change in tap duration. Either I was doing it wrong (always a possibility) or it’s broken…

I assume it is a global value for all tap listeners??

Stu

Hi Stu,

Apologies on this… I just did some more testing, and it appears that the system automatically “waits” for the duration of time you set with “system.setTapDelay()”, and when that duration is up, it reports back how many taps were done in that time… BUT to a maximum of 2 taps. I tried setting the delay to 2 (seconds), which is correct by the way (it’s not supposed to be 2000 as in milliseconds, like with timers). When I tapped on the object multiple times, the max number of hits returned was 2, not like 5.

So, it seems like you can set the delay higher, and Corona will wait for that duration and report back the number of hits within that span… no need to use your own timer or anything. With the delay set to 2 seconds, it ignores the first tap (meaning, it won’t trigger an instant response), but when 2 seconds are up, it reports back the total number.

I would suggest that you test this on whatever devices you have, to ensure it’s working properly at the device level on those devices.

Also, as a side note, I would say that 2 seconds is a bit too high for an actual double tap. 1 second at most, I would suggest. :slight_smile:

Brent