[Use-revolution] Re: Constraining Movement
Sjoerd Op 't Land
sjoerdoptland at mac.com
Tue Nov 27 10:52:01 EST 2001
Mark MacKenzie (Shaw) wrote/ schreef:
> I have a small graphic based group which upon "mousemove" etc. is grabbed by
> the mouse cursor and moved. It is placed (originally and I would like it to
> stay here too!) within the borders an image which is some 3 times the area
> of the moveable graphic. I have been unsuccessful in constraining the
> movement of the graphic group to within this image. The graphic group and
> image are on a card with a much larger image underneath.
>
> There has got to be a fairly straightforward way to do this but I have gone
> round and round without getting this right.
It seems to be easy, but.. at least I had some trouble. I've found a script
that works, but... it can be better:
-------------------------
global dY,dX,tDrag
on mouseDown
put true into tDrag
put item 1 of the mouseLoc - item 1 of loc of me into dX
put item 2 of the mouseLoc - item 2 of loc of me into dY
put dy,dx
end mouseDown
on mouseMove newX,newY
if the mouse is down and tDrag then
if trunc((item 1 of the mouseLoc - dX) + the width of me /
2),trunc((item 2 of the mouseLoc - dY) + the height of me / 2) is within the
rect of image "myImage" and trunc((item 1 of the mouseLoc - dX) - the width
of me / 2),trunc((item 2 of the mouseLoc - dY) - the height of me / 2) is
within the rect of image "myImage" then
set the loc of me to (item 1 of the mouseLoc - dX),(item 2 of the
mouseLoc - dY)
end if
end if
end mouseMove
on mouseUp
put false into tDrag
put empty into dY
put empty into dX
end mouseUp
-------------------------
> I have received a lot of good help and advice on this list, thank you.
>
> Regards Mark
Regards, / Groeten,
Sjoerd
More information about the use-livecode
mailing list