Restricting button movement
Posted: Thu Mar 06, 2014 4:42 am
Okay last post for the evening....I swear!!
I would like to restrict the movement of a button to only the x and y coordinates and prevent the grab command from allowing any diagonal movement. I want to have the buttons on the card move like tiles and only allow movement along the vertical and horizontal axis. I will attach a pic of what I am doing and you will understand what I mean. (hopefully). I am attaching the code I have in each button to allow the buttons to switch places. All of this works fine with the exception to the restriction of movement I am looking for....any suggestions would be greatly appreciated!
[img] [/img]
I would like to restrict the movement of a button to only the x and y coordinates and prevent the grab command from allowing any diagonal movement. I want to have the buttons on the card move like tiles and only allow movement along the vertical and horizontal axis. I will attach a pic of what I am doing and you will understand what I mean. (hopefully). I am attaching the code I have in each button to allow the buttons to switch places. All of this works fine with the exception to the restriction of movement I am looking for....any suggestions would be greatly appreciated!
Code: Select all
global vOldLoc
local vX,vY,vArea
on mouseDown
grab me
set the layer of me to top
--Record the location of the button that was chosen to drag--
put the loc of me into vOldLoc
end mouseDown
on mouseStillDown
--Track the location of the grabbed button--
put the loc of me into vArea
--X location
put item 1 of vArea into vX
--Y location
put item 2 of vArea into vY
--Evaluate x,y movement--
switch
case item 2 of vOldLoc < item 2 of vArea
repeat with x=1 to the number of btns on this cd
if the intersect(me,btn x) then
put the short name of btn x into vName
put the loc of btn x into vLoc
move me to vLoc in 10 ticks
exit repeat
else
end if
end repeat
move btn vName to vOldLoc in 10 ticks
break
case item 2 of vOldLoc > item 2 of vArea
repeat with x=1 to the number of btns on this cd
if the intersect(me,btn x) then
put the short name of btn x into vName
put the loc of btn x into vLoc
move me to vLoc in 10 ticks
exit repeat
else
end if
end repeat
move btn vName to vOldLoc in 10 ticks
break
case item 1 of vOldLoc > item 1 of vArea
repeat with x=1 to the number of btns on this cd
if the intersect(me,btn x) then
put the short name of btn x into vName
put the loc of btn x into vLoc
move me to vLoc in 10 ticks
exit repeat
else
end if
end repeat
move btn vName to vOldLoc in 10 ticks
break
case item 1 of vOldLoc < item 1 of vArea
repeat with x=1 to the number of btns on this cd
if the intersect(me,btn x) then
put the short name of btn x into vName
put the loc of btn x into vLoc
move me to vLoc in 10 ticks
exit repeat
else
end if
end repeat
--Move the button that was intersected to the grabbed buttons first location--
move btn vName to vOldLoc in 10 ticks
break
default
end switch
end mouseStillDown