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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 09 Dec 2008 |
| Total Posts: 5320 |
|
|
| 15 Dec 2015 09:56 AM |
That's what I was hoping for. Thanks. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 09 Dec 2008 |
| Total Posts: 5320 |
|
|
| 15 Dec 2015 10:09 AM |
| Ah thanks. That explains it. |
|
|
| Report Abuse |
|
|
| |
|
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 |
|
|