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

How Can I Keep a GUI In a Constant Position Despite Screen Size?

Asked by 5 years ago

I don't understand AnchorPoint or Position well enough to figure out how to get a GUI to remain in a constant relative position despite my screen size. I am trying to make an inventory GUI that tweens out from the left edge of the screen (meaning most of it shouldn't be visible when its not opened); however, when I stretch my window to a different size, the part of the GUI that should be hidden beyond the left edge becomes visible. How would I go about fixing this? Here is my code if that means anything:

local TweenService = game:GetService("TweenService")
local inventory = script.Parent.Parent

function onClicked(GUI)
    local openGoal = {}
    openGoal.Position = UDim2.new(0.02, 0, .5, 0)
    local closeGoal = {}
    closeGoal.Position = UDim2.new(-0.1, 0, .5, 0)

    local tweenInfo = TweenInfo.new(2)
    local openInventory = TweenService:Create(inventory, tweenInfo, openGoal)
    local closeInventory = TweenService:Create(inventory, tweenInfo, closeGoal)

    local curr_pos = inventory.Position

    if curr_pos.X.Scale <= -.09 then
        openInventory:Play()
    else if curr_pos.X.Scale >= 0.019 then
        closeInventory:Play()
    end
    end
end
script.Parent.MouseButton1Click:connect(onClicked)
0
AnchorPoint should be set to 0.5, 0.5 (most of the time). To get the gui to stay the same Size no matter the screen size set Size to be something like {0.2, 0},{0.2, 0}. The same thing goes for Position. DalekAndrew99 20 — 5y
0
The Position should be something like {1, 0},{0.5, 0} (assuming your gui comes out from the right if its left then {0, 0},{0.5, 0} ) DalekAndrew99 20 — 5y
0
So, I have a Frame inside of the frame being moved. Is that causiing a problem? I've made the main frame (the one that is moving, have all the stuff you said). corncob567 275 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

One way do keep a GUI in the middle of a screen no matter the device is to set AnchorPoint to 0.5, 0.5 and Position should be set to {0.5, 0},{0.5, 0} this way centers your GUI in every devices screen no matter the size of the device. Hope this helps!

Ad

Answer this question