I’m making an app and I want to make an image “snap” to a point.
I have an idea but I don’t really know the “right” code.
The idea is this…
I create the image in the createScene-- imageA, in x=100, y=100
then I create another image, imageB, x=800, y=600.
I have a function that I can move the image B where ever I want
local function plantTouch( event ) if "began" == event.phase then plant.isFocus = true --audio.play (testTouch) plant.x0 = event.x - plant.x plant.y0 = event.y - plant.y elseif bed.isFocus then if "moved" == event.phase then plant.x = event.x - plant.x0 plant.y = event.y - plant.y0 elseif "ended" == phase or "cancelled" == phase then plant.isFocus = false end end -- Return true if the touch event has been handled. return true end
What I need is a function like this –
local function snapImage ( )
if imageB.x == imageA.x or 20 px more or less in any direccion then
imageB.x = imageA.x
end
end
This is the idea, but I don’t really know how to make it work
Also, where do I put the function, all the way up
or make a runtime:listener and wait until the imageB.x is close to imageA.x
Please I need help.
Thanks