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

How would you center a gui?

Asked by 10 years ago

I know your not supposed to ask for scripts on this website but is there a script that can perfectly center a gui?

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

There's no script that centers it. It's all up to you. For the sizing, I recommend using the X and Y offsets (first number in each bracket) so that's it's scaled properly. Once you've done that, do the same for positioning. .5 is for the middle, but since you sized it, you'll have to do a little bit of math.

Say your GUI X Size is {0.2,0}. The positioning for that would be {0.3,0}. Just subtract the size from .5 and you're good.

Ad
Log in to vote
0
Answered by
ipiano 120
10 years ago

You actually don't need a script for this.

You want it perfectly centered on the screen? Basically, you set the Position to 0.5,0,0.5,0 which puts the top corner in the middle of the screen, and then you subtract the width and height.

If the width and/or height is a scaled value, then you subtract that much from the corresponding part of the position and divide by to, and if they are absolute values, you subtract half that much absolute. Here's a couple examples.

If you have a GUI such that size = 0.3,0,0.5,0 then you would want to position it at (1-0.3)/2,0,(1-0.5)/2,0 or, without the math there, it's position is 0.35,0,0.25,0

If you have a GUI such that size = 0,50,0,100 then you would want to position it at 0.5,-50/2,0.5,-100/2 or, without the math there, it's position is 0.5,-25,0.5,-50

And if the size is a combination of scaled and absolute values, then you just do both of the examples at the same time.

Answer this question