I am relatively new to Corona so I apologize in advance if this is a dumb question. I’ve searched the forum and not found anything like this, so here it goes.
The scenario I am attempting to create is one where an object onscreen moves at a constant speed towards wherever the user is currently touching. So, if a touch is begun, the object starts moving towards the touch start position. But, if the user drags their finger, the object would stop its current transition and start moving towards the new finger position. This would continue until the user ended the touch event.
I have this working in some regards, but problematically. If the user taps the screen, the objects moves towards the tap. If, during the middle of that movement, the user taps the screen again, the object immediately starts moving towards the new tap position.
The problem that I am running into is during the drag phase. There is a visible, very jaunty effect that occurs as the user drags their finger on the device.
I was hoping that someone could help me along or point me in the right direction. You can see the code that I am using below.
Thanks!
\_W = display.contentWidth \_H = display.contentHeight local frog = display.newRect(0,0,50,50) frog:setReferencePoint(display.CenterReferencePoint) frog.x = \_W / 2 ; frog.y = \_H / 2 local currentTransition local xStart local yStart local function moveFrog(event) if currentTransition ~= nil then transition.cancel( currentTransition ) end if event.phase == "began" then xStart = event.xStart yStart = event.yStart elseif event.phase == "moved" then xStart = event.x yStart = event.y elseif event.phase == "ended" then xStart = event.x yStart = event.y end distance = math.sqrt((event.x-frog.x)^2+(event.y-frog.y)^2) speed = 0.1 currentTransition = transition.to(frog,{time = (distance / speed),x = xStart , y = yStart}) end Runtime:addEventListener("touch", moveFrog)