[Use-revolution] Re: Constraining Movement
Ken Ray
kray at sonsothunder.com
Tue Nov 27 11:55:01 EST 2001
That's great, Sjoerd!
I took what you had and cleaned it up a bit (hope you don't mind)... here it
is:
-------------------------
global dY,dX,gDrag,x1,y1
on mouseDown
put true into gDrag
put the mouseH - item 1 of loc of me into dX
put the mouseV - item 2 of loc of me into dY
put (the width of me / 2) into x1
put (the height of me / 2) into y1
end mouseDown
on mouseMove newX,newY
if the mouse is down and gDrag then
put the mouseH - dX into offsetMouseH
put the mouseV - dY into offsetMouseV
if trunc(offsetMouseH + x1),trunc(offsetMouseV + y1) is within the rect
of grc "Box" and \
trunc(offsetMouseH - x1),trunc(offsetMouseV - y1) is within the rect
of grc "Box" then
set the loc of me to offsetMouseH,offsetMouseV
end if
end if
end mouseMove
on mouseUp
put false into gDrag
put empty into dY
put empty into dX
put empty into x1
put empty into y1
end mouseUp
-------------------------
Enjoy!
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
----- Original Message -----
From: "Sjoerd Op 't Land" <sjoerdoptland at mac.com>
To: <use-revolution at www.runrev.com>
Sent: Tuesday, November 27, 2001 9:48 AM
Subject: Re: Constraining Movement
> 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