[Use-revolution] Re: Constraining Movement
Geoff Canyon
gcanyon at inspiredlogic.com
Tue Nov 27 14:05:01 EST 2001
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