I want to keep a frame on screen when it goes out of screen. In my game you hover over a frame, a frame pops up on your mouse while you’re hovering showing info of an item. I’d like to keep that frame on screen like on discord. When you right click on a person a frame pops up and it doesn’t go outside of discord even if you right click on the person at the bottom. I’d like to know if there’s a formula for this.
You can check the distance between your mouse and the end of the screen, and if the distance has less pixels than it would be needed to display the whole frame set the frame pivot to bottom.
Get the screen size of the player’s screen and get the size of the Gui. You can then perform arithmetic and check if the Gui is off the screen. Assuming your anchor point is at {0.5,0.5}, you can do: if gui.position.Y + (gui.size.Y/2) < screensize.Y then -- shift the gui up by (gui.size.Y/2) + 20
I don’t exactly remember how Gui is positioned on screen but it’s similar. You take the screen size, then you take the Gui size. If the anchor point is in the middle (when you take position, it takes it from anchor point I believe), then you simply to position.Y +/- (guisize.Y/2) (dont know what the dimension is called but you basically add/subtract half of the ‘height’ of the Gui) < screensize.Y (the height). If the number is lower/higher it means the Gui is offscreen. From there you want to increase/decrease the gui position Y value to put it on the screen.