Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I place a gui in the exact middle for all computer monitor resolutions? [closed]

Asked by 8 years ago

I'm having the problem that if this load gui I made changes resolutions, the positions will be inaccurate. So how do I put my stuff exactly in the middle of a Frame?

Locked by User#19524

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
7
Answered by 8 years ago

Here's the formula: {0.5, -AbsoluteSize.X / 2, 0.5, -AbsoluteSize.Y / 2}

Here's a breakdown:

Scale

Scale is a number that mainly ranges from 0-1 (but can be set to any other number), and it's basically a number referring to what percent of the gui's parent's window the gui will be sized or positioned to. For example, if there is a frame that is sized {0, 100, 0, 100}, and a frame that was a child of that frame was sized {1, 0, 1, 0}, the child frame would fill the whole frame because 1 is 100% of the whole frame, just like 0 would be 0%

In our case, 0.5 means half of the whole frame, which in our case is the screen. This means that the top left corner of the gui will always be positioned at exactly the middle of the screen

Offset

Offset is a number that describes the number of pixels to offset. For example, in a frame that is sized {0, 100, 0, 100}, a child frame that has a size of {0, 100, 0, 100} would fill up the whole frame.

In our case, we want to move the gui up and left in order to center it because only the top left corner is the in the center. In order to do that, we need to move it up by half the Y size, and move it left by half the X size. That way, you can center the gui perfectly.

For example, if you had a gui that is sized {0, 100, 0, 100}, you would center it by setting the position to this: {0.5, -50, 0.5, -50}

Hope this helped!

Note: It is highly suggested you use the AbsoluteSize property to determine the offset for the position, because if you have a gui that is sized {0.25, 100, 0.1, 200}, it won't be centered if you use the "negate and half the offset" method. The AbsoluteSize property shows you the size of the gui in pixels, hence "AbsoluteSize". Use the numbers in there instead of the numbers in the Size.

0
Thanks! This really helped. HungryJaffer 1246 — 8y
Ad