Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Centering a Dynamically Scaling GUI?

I know that to center a GUI you would need to divide its pixel size in half.

So Size {0, 500} {0, 500} would need Position {0.5, -250} {0.5, -250}

But with Roblox going on mobile devices I would much rather use a screen percentage (the first number) to size and position my stuff. But then **how would I center the GUI if the size changes based on the screen resolution? **

Size: {0.5, 0} {0.25, 0} Position: {?, ?} {?, ?}

Do I need a script for this?

2 answers

✓ Accepted answer

Quite simple actually. Just set the position to .5 - Half of size. Try this for position:

{.25,0}{.375,0}

If you have any quesitons, please leave a comment below. Hope I helped :P

If the gui size is being resized by the Scale, then there are 2 methods of positioning the Gui.

Method 1

Divide the scale by two to get the position property, like so:

Size: {0.5, 0}, {0.25, 0}

Position: {0.25, 0}, {0.125, 0}

Method 2

Use the traditional gui centering method by dividing and negating the AbsoluteSize property of the Gui itself, like so:

Size: {0.5, 0}, {0.25, 0}

Position: {0.5, -Gui.AbsoluteSize.X / 2}, {0.5, -Gui.AbsoluteSize.Y / 2}

Hope this helped!

1 comment

0

The Y Offset on the first is incorrect. It should be .5-.125, which is .375 . Just letting you know :P

This discussion is preserved as it was. New answers, comments, and votes are closed.