[Use-revolution] Re: Constraining Movement
Ken Ray
kray at sonsothunder.com
Tue Nov 27 15:36:00 EST 2001
Thanks, Geoff! So now we have:
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 pMouseX,pMouseY
if not the uAllowDrag of me then exit mouseMove
put pMouseX - (the dX of me) into offsetMouseH
put pMouseY - (the dY of me) into offsetMouseV
set the loc of me to \
min(max(offsetMouseH,left of img 1 + (width of me/2)),\
right of img 1 - (width of me/2)),\
min(max(offsetMouseV,top of img 1 + (height of me/2)),\
bottom of img 1 - (height of me/2))
end mouseMove
on mouseUp
set the uAllowDrag of me to false
end mouseUp
on mouseRelease
mouseUp
end mouseRelease
(for those of you still paying attention... ;-)
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
----- Original Message -----
From: "Geoff Canyon" <gcanyon at inspiredlogic.com>
To: <use-revolution at www.runrev.com>
Sent: Tuesday, November 27, 2001 1:03 PM
Subject: [Use-revolution] Re: Constraining Movement
> At 10:20 AM -0800 11/27/01, Scott Rossi wrote:
> >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
>
> Somehow the docs on mouseMove keep fooling people (they fooled me until
Kevin pointed this out). mouseMove provides you with two arguments, which
are the coordinates of the mouse. Using those is obviously more efficient
than using the functions to get them again. So the above could become:
>
> on mouseMove pMouseX,pMouseY
> if not the uAllowDrag of me then exit mouseMove
> set the loc of me to \
> min(max(pMouseX,left of img myImg + (width of me/2)),\
> right of img myImg - (width of me/2)),\
> min(max(pMouseY,top of img myImg + (height of me/2)),\
> bottom of img myImg - (height of me/2))
> end mouseMove
>
> Of course, if speed were much of an issue you could also precalculate and
store the values used for comparison.
>
> regards,
>
> Geoff
>
>
More information about the use-livecode
mailing list