Building a Board Game

Quentin Long cubist at
Fri Apr 10 19:03:07 EDT 2020

On 7.04.20 22:24, Roger Guay via use-livecode wrote:
> Hi all,
> I know there must be a simple way to do this but it is escaping me at the moment. How can I move an object (grab me on mouseDown) and have it snap to a grid (square on a board game) on mouseUp?
There are any number of ways to do this thing. Try giving this script to the object you want to move:
local DisX, DisYlocal GridSize = 20-- if grid uses different sizes for X and Y, make GridSizeX and GridSizeYlocal OriginGridX = 10local OriginGridY = 10
on mouseDown  send "TrackDaMouse" to meend mouseDown
on TrackDaMouse  put the mouseLoc into Fred  put GridSize * ((item 1 of Fred - OriginGridX) div GridSize) + OriginGridX into DisX  put GridSize * ((item 2 of Fred - OriginGridY) div GridSize) + OriginGridY into DisY  set the loc of me to Fred  if the mouse is down then    send "TrackDaMouse" to me in 20 msec  else    move me to (DisX, DisY) in .5 seconds  end ifend TrackDaMouse

More information about the use-livecode mailing list