Touch for moving an object

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Touch for moving an object

Post by Mag » Thu Nov 22, 2012 7:35 pm

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?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Touch for moving an object

Post by jmburnod » Thu Nov 22, 2012 10:19 pm

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
https://alternatic.ch

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Touch for moving an object

Post by Mag » Wed Dec 05, 2012 12:11 pm

Thank you so much Jean-Marc! Elegant and efficent code.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Touch for moving an object

Post by jmburnod » Wed Dec 05, 2012 1:27 pm

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
https://alternatic.ch

Post Reply