Moving without transitions

I have an image, and a button. What I am trying to do is move the image when the user presses the button, and stop it when they let go of the button.

I know this is super super simple, but it’s just a lack of experience that is halting my progress.

Is there a way to use transition.to, but force it to stop early? Like if I wanted the image moved no further than 400 x, and when the button is pressed, it starts that transition but when they let go, it stops.

Or is there a better way to do this? I would prefer a fluent movement, maybe a repeat loop or something? Been stuck on this forever!

E: forgot to mention, it is NOT a physics object.

If using a transition you can just save it’s handle to a variable and then use transition.cancel() to stop it. For example:

– Save the handle of the transition

local myTrans = transition.to(object, {x=100, y=200})
 

– Stop the transition

transition.cancel(myTrans)
 

If using a transition you can just save it’s handle to a variable and then use transition.cancel() to stop it. For example:

– Save the handle of the transition

local myTrans = transition.to(object, {x=100, y=200})
 

– Stop the transition

transition.cancel(myTrans)