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

How to convert scale for all screens (without using offset)?

Asked by 5 years ago
Edited 5 years ago

Is there a equation to convert scale to fit all screens?

For instance, I'm adding (0,1,0,0) to a gui at a time, but if I use a different device, such as a phone, laptop or tablet; it won't scale correctly.

I can't use offset (because I'm adding size to the gui), I'm not using tween service either.

Thanks.

0
What do you mean you're moving the gui? It should still be able to keep the right size if you used offset even if it moves to the left side of the screen. yellp1 193 — 5y
0
Sorry, I meant adding size. Gameplay28 139 — 5y

1 answer

Log in to vote
1
Answered by
Fifkee 2017 Community Moderator Moderation Voter
5 years ago
Edited 5 years ago

Scale is determined by dividing the Main GUI's AbsoluteSize by the screen size. If the GUI has a GUIObject parent (By the way, ScreenGuis are not GuiObjects.), then it will divide the Main GUI's AbsoluteSize by the GuiObject parent.

You can get the screen size by getting the camera's viewportsize.

Snippet: ```lua local GuiObject = v:FindFirstAncestorWhichIsA('GuiObject')

local SizeX = v.AbsoluteSize.X / (GuiObject and GuiObject.AbsoluteSize.X or workspace.CurrentCamera.ViewportSize.X)

local SizeY = v.AbsoluteSize.Y / (GuiObject and GuiObject.AbsoluteSize.Y or workspace.CurrentCamera.ViewportSize.Y) ```

0
typo: divide the main gui's absolute size by the parent's absolute size. i've provided a code snippet from my plugin to show. waewawe Fifkee 2017 — 5y
Ad

Answer this question