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

Centering GUIs with the new UIAspectRatioConstraint?

Asked by 7 years ago

I added the UIAspectRatioConstraint to my GUI with a scale of 2 and the dominant axis set to width.

However, I'm only using scale for size and I want it to be centered at my screen at all times. Initially, I thought it was:

{0.5-size.X.Scale, 0, 0.5-size.Y.Scale, 0}

but that doesn't seem to work.

How would I do this?

1 answer

Log in to vote
1
Answered by 7 years ago

Might I recommend AnchorPoint? AnchorPoint is the recently added square that starts by appearing on the Top-left hand side of your GUIObject.

-- || Example ||
GUI.RANDOMGUINAME.AnchorPoint = Vector2.new(0.5,0.5) -- Now it'll center values... Therefore...
GUI.RANDOMGUINAME.Size = UDim2.new(0.5,0,0.5,0) -- This'll be exactly half of the Screen.
GUI.RANDOMGUINAME.Position = UDim2.new(0.5,0,0.5,0) -- This'll center it.


Anyways, I found this out recently. It's actually incredibly useful because back then you'd have to tinker with the numbers just a little to get it perfect.

If this helped, let me know!

Ad

Answer this question