kippereye
December 6th, 2005, 06:49 PM
hi everyone
I have a tooltip that follows the mouse, but i need to to figure out where the edges of the screen are and always keep the tootip on the screen. Its something to do with screen width and height but i cant figure it out .
If anyone can help i`d be greatful
cheers
kippereye
icio
December 6th, 2005, 06:58 PM
Here's a nicely cut down piece of code:
tooltop._x = Math.max(0, Math.min(_xmouse, Stage.width-tooltip._width));
tooltip._y = Math.max(0, Math.min(_ymouse, Stage.height-tooltip._height));
Now, this may look a little complicated at first, but let me explain it to you.
First of all, remind yourself that for positions to the right of other positions, `_x` is greater and that for positions below other position, `_y` is greater.
So lets look at the `Math.min` function usage here. `Math.min` returns the lower value of the two values given to it. In this case, it is being used to give the left-most `_x` value and top-most `_y` value. The two values given are `Stage.width-tooltip._width`/`Stage.height-tooltop._height` and `_xmouse`/`_ymouse`. So this piece of code handles constraints for the right and bottom of the screen.
The max value works in the same way, except it returns the right-most `_x` and bottom-most `_y`. This handles the top and left constraints.
Hope this helps :thumb:
kippereye
December 6th, 2005, 08:03 PM
yes got it thanks for this
kippereye
icio
December 7th, 2005, 02:10 PM
welcome (-:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.