Tapping a moving shape

Hi everybody.

Why can’t I tap on the circle while it’s in transition and print the coordinates?

local function onObjectTap( self, event )
 local TapX = event.x
    local TapY = event.y
 print (“circle tapped: (”… TapX … “,” … TapY … “)”)
end

local myCircle = display.newCircle (300,300,200)
myCircle.tap = onObjectTap
myCircle:addEventListener( “tap”, myCircle )

transition.to( myCircle, { time=2000, x=500 ,y=1000, delta=true } )

Can it not listen while moving?

It’s fine once it finishes moving.

I’m I doing it wrong? Should I be using something else to animate/move the circle?

Thanks

Ken

Your code runs correctly and doesn’t have any errors. You are probably experiencing issues due to two reasons.

First, the object moves fast in the transition and you may not have adequate time to  tap  the circle given the speed. Just add a zero at the end of your transition time and you’ll see that it works.

Second, you are using a tap listener, not a touch listener. Tap events are simply touching/pressing down and letting go. If you move your finger or cursor while holding down, you are looking at a touch event. It is possible that you are accidentally swiping as you are trying to tap the fast moving object.

Hi XeduR @Spyric , Thanks for the reply. Yeah it does work when it’s on the phone. Maybe my computer isn’t fast enough to know I clicked on the circle.

Your code runs correctly and doesn’t have any errors. You are probably experiencing issues due to two reasons.

First, the object moves fast in the transition and you may not have adequate time to  tap  the circle given the speed. Just add a zero at the end of your transition time and you’ll see that it works.

Second, you are using a tap listener, not a touch listener. Tap events are simply touching/pressing down and letting go. If you move your finger or cursor while holding down, you are looking at a touch event. It is possible that you are accidentally swiping as you are trying to tap the fast moving object.

Hi XeduR @Spyric , Thanks for the reply. Yeah it does work when it’s on the phone. Maybe my computer isn’t fast enough to know I clicked on the circle.