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

GUI not centering

Asked by
TomsGames 225 Moderation Voter
10 years ago

Alright, so I have a screengui in startergui, then a frame, then an imagelabel.

The imagelabel is this size:

{0, 100}, {0, 100}

So the way I learn it, 1 - 0.1 = 0.9 0.9/2 = 0.45

So I should put the position at..

{0.45 0}, {0.45, 0}

To centre it. Right?

Well it's not working, and it is a bit to the left of the centre.

The frame is at 1, 0 1, 0

So that shouldn't be an issue.

Am I doing something wrong?

3 answers

Log in to vote
10
Answered by 10 years ago

If you want to center your gui on screen with the size {0, 100}, {0, 100}, you should use the following formula for position:

Simplified Forumula (Offset only)

{0.5, -(width / 2)}, {0.5, -(height / 2)}

General Formula (Both scale and offset)

{0.5 - (xScaleSize / 2), -(xOffsetSize / 2)}, {0.5 - (yScaleSize / 2), -(yOffsetSize / 2)}

In this case, it would be

{0.5, -50}, {0.5, -50}

2
I've downvoted your answer, because while this is the simplified formula, you should also give the generalized formula (to incorporate scale AND offset), which is UDim2.new(0.5-xScaleSize/2, -xOffsetSize/2, 0.5-yScaleSize/2,-yOffsetSize/2). Edit it to receive my upvote. TheLuaWeaver 301 — 10y
1
Ohhhhh kill em ConnorVIII 448 — 10y
Ad
Log in to vote
4
Answered by
digpoe 65 Badge of Merit
10 years ago

A better way is to do something like this:

local gui = script.Parent
local size = gui.AbsoluteSize
gui.Position = UDim2.new(0.5, -size.X/2, 0.5, -size.Y/2)

it perfectly centers the Gui, and it will always be centered on every screen.

Log in to vote
-3
Answered by 10 years ago

What would the position be instead of scripting the position. I have a button which moves and I want to know the position, so that I can position it to what the script is saying.

0
wait what Zenith_Lord 93 — 6y

Answer this question