[resolved] is there a way to retrieve the last y x, y coordinates?

What I want to do is that the user drags a picture to a specific spot, but if he release and its not on that specific spot it goes back to its original position.

What ive done is just put the x,y it had before, but the problem with this is that the user is able to add pictures, and i want that function to pass on to all images, of returning it to its original position without me explisity giving it the exact coordinates.

Is there a way or code so the program can store the initial x and y? Ive thought of creating a variable that stores that info but i dont know how to get those coordinates…

any help? [import]uid: 123133 topic_id: 23684 reply_id: 323684[/import]

I tried to store the x and y at the began phase but that didnt work… here is what i did:

[lua]local function drag ( event )

local t = event.target
local phase = event.phase

if “began” == phase then
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t, event.id )

t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y

local Initialx = t.x
local Initialy = t.y

elseif t.isFocus then

if “moved” == phase then

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( t, nil )
t.isFocus = false

else
t.x = Inicialx
t.y = Inicialy

end


…[/lua]

it just moves the picture over to the top left for some reason… [import]uid: 123133 topic_id: 23684 reply_id: 95150[/import]

You say InitialX/InitialY at first but then InicialX/InicialY later, which probably would mean nil hence it goes to the top left.

Anyway, what you should do is pre-declare outside of the execution. It’s hard to say where but to keep it easy just declare before the event function.

local InitialX, InitialY local function drag ( event )

That way, inside the function you can still give InitialX and InitialY a value, but they exist outside and any future calls of drag() can use those numbers.

If you want only that one click event to use the numbers, then just move the declarations inside. [import]uid: 41884 topic_id: 23684 reply_id: 95175[/import]

o wow… that was it … lol thanks [import]uid: 123133 topic_id: 23684 reply_id: 95222[/import]