Page 1 of 1

Touch for moving an object

Posted: Thu Nov 22, 2012 7:35 pm
by Mag
Hi all, I'm following this tutoria <...lessons/m/4069/l/11493-how-do-i-use-multi-touch-to-move-more-than-one-object> and all works well, the only problem I found is that when you touch the object, it moves under the finger instead of remaining in the initial position. I think I could solve by subtracting the distance between the touch and the center of the object from the position to assign. Unfortunately I can not find an elegant way to capture this data. Has anyone solved a similar problem?

Re: Touch for moving an object

Posted: Thu Nov 22, 2012 10:19 pm
by jmburnod
Hi Mag,

You can use something like that:

Code: Select all

local sCurObj,sX,sY,sWork
on mousedown
   put the short name of the target into sCurObj
   put (the mouseH - item 1 of the loc of btn sCurObj) into sX
   put (the mouseV - item 2 of the loc of btn sCurObj) into sY
   put true into  sWork
end mousedown

on mousemove x,y
   if sWork and  sCurObj <> empty then
      put x-sX into tNewH
      put y-sY into tNewV
      set the loc of btn sCurObj to tNewH,tNewV
   end if
end mousemove

on mouseup
        put false into  sWork
end mouseup
Best regards

Jean-Marc

Re: Touch for moving an object

Posted: Wed Dec 05, 2012 12:11 pm
by Mag
Thank you so much Jean-Marc! Elegant and efficent code.

Re: Touch for moving an object

Posted: Wed Dec 05, 2012 1:27 pm
by jmburnod
Hi Mag,
Welcome.I'm glad when i can help and pass what I received
We are more clever when we share knowledge
Best
Jean-Marc