Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

tap-able object on touch-able background - does touch-listener always fire first?
Started by CoronaChris Nov 18 2018 08:17 AM

4 replies to this topic

Best Answer roaminggamer , 18 November 2018 - 08:49 AM

Corona is single threaded, so "No, a tap with a small amout of code can't 'sneak in'."

 

Once a piece of Lua code (a listener for example) starts to execute, it will complete uninterrupted.

 

All processing is sequential.

 

PS - You can answer your question experimentally.  Once you know the order (either tap before touch or touch before tap) you are good to do.  It won't change in future versions of Corona.  If it did, that would be a bug worth filing.

 

PPS - I don't typically use tap, for this and other reasons.  You can always just use touch exclusively and handle the double-tap logic yourself.  This will then insulate you from any possible future changes.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

CoronaChris

[GLOBAL: userInfoPane.html]
CoronaChris
  • Contributor

  • 162 posts
  • Corona SDK

Dear Corona community,

 

lets say I have a red rectangle on a white larger background rectangle. My red rectangle has a tap-listener printing "tapped", my white background has a touch-listener printing "touched" in ended-phase. When I look in console, the touch event prints first.

 

My questions are:

 

1) If I don't change my code: Will my touch-event always fire before my tap event?

2) If I put more and more "actions" (adding/removing stuff) into my touch-listener ended-phase and keep the print-statement at the end, would my tap-print-statement fire first at some point?

 

Background-information: I have a scrollView with a scrollListener that starts a transition in the ended-phase. In this scrollview I have a text-object with a tap-listener on it among other objects. When I tap on that text-object, I call composer.gotoScene and I'd like to cancel all transitions.

 

Calling transition.cancel() in my tap-listener perfectly works, I'm just wondering if that is always the case or if I could - technically - make the tap-listener fire first, which would result in canceling nothing since the transition would occur after.

 

Would appreciate any help here :)

 

Thanks



[TOPIC: post.html]
#2

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,259 posts
  • Enterprise

the touch-began phase will always* fire before its tap event (if the tap event even fires) - because the "tap" event is essentially just a touch began+ended that occurs within x milliseconds, so tap can't fire until the corresponding touch-ended event has also occurred (because otherwise it's just a "long touch" rather than a "tap")

 

*caveat:  this is only from experience rather than any insider engineering knowledge - so i suppose there might be some way engineering could at some point change this, perhaps "deferring" the touch-began event, but i highly doubt it as it would be a major breaking change, it's been safe behavior to rely on even though not formally documented



[TOPIC: post.html]
#3

CoronaChris

[GLOBAL: userInfoPane.html]
CoronaChris
  • Contributor

  • 162 posts
  • Corona SDK

Thanks dave. That all makes sense, but I'm afraid I haven't explained it clear enough:

 

I understand a tap cant fire until the corresponding touch-ended phase has occurred. But what exactly does "occurred" mean? Do the end-phase and the tap start at the same time? Or does the tap-event wait until all the things in the end-phase are "done"?

 

As my question nr. 2 tries to make clear: Can I load so many code into my end-phase with a print-statement at the end so that the tap print fires fires first since it has nothing but a print-statement?



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,380 posts
  • Corona SDK

  Best Answer

Corona is single threaded, so "No, a tap with a small amout of code can't 'sneak in'."

 

Once a piece of Lua code (a listener for example) starts to execute, it will complete uninterrupted.

 

All processing is sequential.

 

PS - You can answer your question experimentally.  Once you know the order (either tap before touch or touch before tap) you are good to do.  It won't change in future versions of Corona.  If it did, that would be a bug worth filing.

 

PPS - I don't typically use tap, for this and other reasons.  You can always just use touch exclusively and handle the double-tap logic yourself.  This will then insulate you from any possible future changes.


  • Alan PlantPot likes this

[TOPIC: post.html]
#5

CoronaChris

[GLOBAL: userInfoPane.html]
CoronaChris
  • Contributor

  • 162 posts
  • Corona SDK

That's good to know (and makes sense), so I can leave my code as it is. Thanks Ed :)




[topic_controls]
[/topic_controls]