tap and touch listeners on same object - tap also triggers touch

Dear corona community,

I would like to listen for both tap and touch events on the same object and do different transitions to it, depending on whether it was a touch or a tap. Problem: The tap events also fire the touch listener, so two transitions are happening.

Following the tutorial here: https://coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

I can have both a tap and a touch listener on the same object and use something like this:

function comboListener( event )    if ( event.phase ) then         print(" TOUCHED!" )         votePic1(event)    else         print(" TAPPED!!!")         focusPic1(event)    end    return end object:addEventListener("touch", comboListener) object:addEventListener("tap"; comboListener)

to distinct between the two.

Problem is: If I just mouseclick on the object in the simulator, console prints out:

14:32:17.552 TOUCHED! 14:32:17.552 votePic1 14:32:17.643 TOUCHED! 14:32:17.643 votePic1 14:32:17.643 TAPPED!!! 14:32:17.643 focusPic1

So, touch event gets fired twice, tap event gets fired once. What am I doing wrong here?

Ok, I now see that this is a normal behaviour. Touch fires twice because of begin and ended phase. Now, the question is: How can I distinguish between the ended phase and the tap-listener? Simplified:

My object gets moved to x = 100 in my touchlistener’s ended phase after the object is dragged via user’s finger, and gets moved to x = 200 in my tap-listener when user just taps the object. How can I achieve this? Right now both transitions are fired…

you just need a touch listener for doing what you want. just use a variable to check the time you press the object, if it’s lower than 300ms for example then you can consider it a tap event, if its higher you can trigger what you want as a touch event.

that sounds like a plan, I’ll do that. Thanks carloscosta :slight_smile:

Ok, I now see that this is a normal behaviour. Touch fires twice because of begin and ended phase. Now, the question is: How can I distinguish between the ended phase and the tap-listener? Simplified:

My object gets moved to x = 100 in my touchlistener’s ended phase after the object is dragged via user’s finger, and gets moved to x = 200 in my tap-listener when user just taps the object. How can I achieve this? Right now both transitions are fired…

you just need a touch listener for doing what you want. just use a variable to check the time you press the object, if it’s lower than 300ms for example then you can consider it a tap event, if its higher you can trigger what you want as a touch event.

that sounds like a plan, I’ll do that. Thanks carloscosta :slight_smile: