[Use-revolution] Re: Constraining Movement

Ken Ray kray at sonsothunder.com
Tue Nov 27 15:30:01 EST 2001


Scott,

I like yours because you can "slide" around the edges of the bounding
rectangle. However, the mouseDown-ed object's loc still snaps to the
mouseLoc. Here's a revised version that doesn't do that:

on mouseDown
  set the uAllowDrag of me to true
  set the dX of me to (the mouseH - item 1 of loc of me)
  set the dY of me to (the mouseV - item 2 of loc of me)
end mouseDown

on mouseMove
  if not the uAllowDrag of me then exit mouseMove
  put the mouseH - (the dX of me) into offsetMouseH
  put the mouseV - (the dY of me) into offsetMouseV
  set the loc of me to \
      min(max(offsetMouseH,left of img myImg + (width of me/2)),\
      right of img myImg - (width of me/2)),\
      min(max(offsetMouseV,top of img myImg + (height of me/2)),\
      bottom of img myImg - (height of me/2))
end mouseMove

on mouseUp
  set the uAllowDrag of me to false
end mouseUp

on mouseRelease
  mouseUp
end mouseRelease

I love this collaboration! :-)

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/

----- Original Message -----
From: "Scott Rossi" <scott at tactilemedia.com>
To: <use-revolution at www.runrev.com>
Sent: Tuesday, November 27, 2001 12:20 PM
Subject: Re: Constraining Movement


> Recently, Mark MacKenzie (Shaw) wrote:
>
> > 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.
>
> Here's another (simpler?) option that seems to work for me:
>
> on mouseDown
>   set the uAllowDrag of me to true
> end mouseDown
>
> on mouseMove
>   if not the uAllowDrag of me then exit mouseMove
>   set the loc of me to \
>       min(max(the mouseH,left of img myImg + (width of me/2)),\
>       right of img myImg - (width of me/2)),\
>       min(max(the mouseV,top of img myImg + (height of me/2)),\
>       bottom of img myImg - (height of me/2))
> end mouseMove
>
> on mouseUp
>   set the uAllowDrag of me to false
> end mouseUp
>
> on mouseRelease
>   mouseUp
> end mouseRelease
>
>
>
> Regards,
>
> Scott
>
> _____________________________________________________________________
> Scott Rossi                       Tactile Media - Multimedia & Design
> Creative Director                 Email: scott at tactilemedia.com
>                                   Web: www.tactilemedia.com
>
>




More information about the use-livecode mailing list