[Use-revolution] Re: Constraining Movement

Scott Rossi scott at tactilemedia.com
Tue Nov 27 14:13:00 EST 2001

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
end mouseRelease



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