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

How do I use an UIAspectRatioConstraint? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

There are no tutorials on this and I cant seem to figure out how to keep the frame onto the screen using this method. I also don't know if I have to use code to do this.

1 answer

Log in to vote
1
Answered by
ABK2017 406 Moderation Voter
6 years ago
Edited 6 years ago

A UIAspectRatioConstraint ensures that a GuiObject maintains a particular aspect ratio even if it’s size is set as a percentage of its parent. If an object with this constraint is also under the control of a UILayout such as UIGridLayout, then the constraint controls the object’s size and overwrites any size the layout would apply.

A UIAspectRatioConstraint can be applied to a GuiObject by parenting it to that object.

When applied to a GuiObject, the UIAspectRatioConstraint will make sure that the object’s ratio is maintained by the value defined in AspectRatio. The AspectType sets what determines the maximum size of the object. When set to FitWithinMaxSize, the constraint will make the object the maximum size it can be within the AbsoluteSize of the element. When set to ScaleWithParentSize, the element’s maximum size will be the size of the parent while still maintaining the aspect ratio. Last, the DominantAxis will determine which axis to use when setting the new size of the element.

--Example 
 GUI.RANDOMGUINAME.AnchorPoint = Vector2.new(0.5,0.5) -- Now it will center values. 
 Therefore...
 GUI.RANDOMGUINAME.Size = UDim2.new(0.5,0,0.5,0) -- This will be half of the screen.

 GUI.RANDOMGUINAME.Position = UDim2.new(0.5,0,0.5,0) -- This will center it.

Example of SizeConstraint within your GUI script

local gui = script.Parent
local parent = gui.Parent

local function update()
    gui.SizeConstraint =
        parent.AbsoluteSize.x < parent.AbsoluteSize.y
        and Enum.SizeConstraint.RelativeYY
         or Enum.SizeConstraint.RelativeXX
end

update()
parent:GetPropertyChangedSignal("AbsoluteSize"):Connect(update)
0
Whenever I make the UIAspectRatioConstraint the parent of the frame it makes it go off the screen RichCookieGamer 7 — 6y
0
Have you tried using SizeConstraint? Or does the image need to scale? ABK2017 406 — 6y
0
I will try that RichCookieGamer 7 — 6y
0
The width is supposed to be consistent while the height is not...Are you using it in a single frame, or a frame within another frame? ABK2017 406 — 6y
View all comments (11 more)
0
I need the frame to stay in that position even if it has to scale, and the size and scale constraint both went off the screen RichCookieGamer 7 — 6y
0
I am using a single frame RichCookieGamer 7 — 6y
0
Ok, I edited my answer to include a SizeConstraint example ABK2017 406 — 6y
0
I asked because descendants of frames, the width(x) if in offset, will offset all descendants whether they're using scale or not ABK2017 406 — 6y
0
Do I have to make a script for this to work? Otherwise the frame just goes off the screen somewhere when I put it in the constraints RichCookieGamer 7 — 6y
0
I am supposed to make the constraints the parent too right RichCookieGamer 7 — 6y
0
The SizeContrstraint would be part of a script yes...I'm not sure what you want your frame to look like, but an example file is at ABK2017 406 — 6y
0
UIConstraint in the Image Label, UIARC in PlayDockContainer ABK2017 406 — 6y
0
So I make the Sizeconstraint's parent the frame not the frame's parent being the Sizeconstraint RichCookieGamer 7 — 6y
0
I also have an issue where I have explorer open and its on the right of my screen but it doesn't make the game screen more compact RichCookieGamer 7 — 6y
Ad

Answer this question