generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Maintaining GUI Aspect Ratio as Screen is Resized.

Previous Thread :: Next Thread 
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 09:37 AM
Basically I'm looking for an equation to keep the aspect ratio of a GUI the same no matter what dimension the screen size is.

This way I can resize the GUI to fit on the screen while keeping its shape.
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
15 Dec 2015 09:41 AM
Use offset and then position to your liking, using Scale if you want the GUI to move 'with the screen' as the screen gets smaller/bigger.

Center = {0.5,half the scale of your size, 0.5, half the scale of your size}


http://www.roblox.com/--item?id=79103594
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
15 Dec 2015 09:42 AM
edit:

Center = {0.5, -half the scale of your size, 0.5, -half the scale of your size}

forgot minus


http://www.roblox.com/--item?id=79103594
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 09:47 AM
Scale doesn't maintain aspect ratio, scale stretches your GUI.
Report Abuse
DermonDarble is not online. DermonDarble
Joined: 04 Jun 2015
Total Posts: 2576
15 Dec 2015 09:50 AM
Use scale and set the sizeconstraint to xx or yy

/I wanted to be a better brother, better son/
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 09:55 AM
That works I guess, not sure what was going on in my head.
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
15 Dec 2015 09:56 AM
I actually wrote code that does this perfectly:

local desiredRes = Vector2.new(900,582)
local c = workspace.CurrentCamera
local baseUI = script.Parent

local function updateRes()
local currentRes = c.ViewportSize
local aspectRatio = currentRes.X/currentRes.Y
local uiRatio = (currentRes.X/currentRes.Y)/(desiredRes.X/desiredRes.Y)
if uiRatio < 1 then
local height = (desiredRes.Y/desiredRes.X) * currentRes.X
baseUI.Size = UDim2.new(1,0,0,height)
baseUI.Position = UDim2.new(0,0,0.5,-height/2)
elseif uiRatio > 1 then
local width = (desiredRes.X/desiredRes.Y) * currentRes.Y
baseUI.Size = UDim2.new(0,width,1,0)
baseUI.Position = UDim2.new(0.5,-width/2,0,0)
else
baseUI.Size = UDim2.new(1,0,1,0)
baseUI.Position = UDim2.new()
end
end

local function onCameraChanged(property)
if property == "ViewportSize" then
updateRes()
end
end

updateRes()
c.Changed:connect(onCameraChanged)
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 09:56 AM
That's what I was hoping for.
Thanks.
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
15 Dec 2015 09:59 AM
Well, almost perfectly.
I still need to tweak it to ignore the top bar, but that can be fixed relatively easily.
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 10:04 AM
Is it meant to stretch the Frame across the whole width of the screen?
The X scale seems to be stuck on 1.

This my desired Res : local desiredRes = Vector2.new(250,50)
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
15 Dec 2015 10:08 AM
Oh sorry, I forgot to explain this.
The frame is supposed to hold all your gui objects inside of it, and you specify the perfect screen size for the UI to look correct.

If the screen is too wide, the frame will be as tall as the screen, and it will have a width relative to the desired width to height ratio, and vice versa.
Report Abuse
opplo is not online. opplo
Joined: 09 Dec 2008
Total Posts: 5320
15 Dec 2015 10:09 AM
Ah thanks. That explains it.
Report Abuse
Deafgift100 is not online. Deafgift100
Joined: 09 May 2010
Total Posts: 3958
15 Dec 2015 10:16 AM
thanks clone!
Report Abuse
iWindowz is not online. iWindowz
Joined: 05 Jan 2013
Total Posts: 1809
15 Dec 2015 10:29 AM
@opp
i meant scale for positioning, and offset for sizes


http://www.roblox.com/--item?id=79103594
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image