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

Is there anyway of scaling a GUI opposing to the player's screen size?

Asked by 3 years ago

Hi, I'm just wondering if there is a possible way of doing so because I keep using this technique most of time and It's getting quite annoying managing 2 GUIS at the same time. I tried looking on dev forums and any code samples.

if  game:GetService("UserInputService").TouchEnabled == true then
      script.Parent.Visible = true
end
local Frame1 = script.Parent:WaitForChild("Frame1")
local Frame2 = script.Parent:WaitForChild("Frame2")

Frame1.Size.X =  game.Workspace.CurrentCamera.ViewportSize
Frame1.Size.Y =  game.Workspace.CurrentCamera.ViewportSize

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

In every GUI there is a property called 'size': (You probably know that!)

lets say our size was {0, 100},{0, 100}, the default roblox frame size.

Now you may be wondering why there are 4 numbers when rescaling happens by 2 axis.

well, the first number in each bracket (which are both 0) are the proportions of size, so if it was 0.5, it would take up 50% of your screen no matter what device, and the 2nd number in each bracket (which are both 100) are the offset, the size of GUI on your device only.

So lets wrap this up:

If you wanted to make a GUI fit on every device, just set the offset to 0: {0, 0},{0, 0}, and just drag and resize it to your liking! - so no need to detect if the user is a mobile user!

Hope this helps!

Any questions? just ask!

** PS - THERE ARE ALSO PLUGINS THAT CAN DO THIS FOR YOU - HERE IS THE ONE I USE!

Ad

Answer this question