I have a perfect square gui object that i am attempting to tween while keeping it a perfect square, how do I do this? My code is down below and is as precise as I have been able to get it to.
1 | player.PlayerGui.ScreenGui.Frame:TweenSize(UDim 2. fromScale(. 05 * 1.10 , 0.17 * 1.34 ), "Out" , "Linear" , 2 ) |
2 | player.PlayerGui.ScreenGui.Frame:TweenPosition(UDim 2. fromScale(. 985 *. 881 ,. 985 *. 453 ), "Out" , "Linear" , 2 ) |
3 | --[[^as a side note, this is where im trying to offset it to keep the center position on the screen. if you know a good way to do this, help me out]] |
For a perfect square object, roblox has created a very useful tool which automatically keeps your GUI objects at a certain ratio. This even works with from scale, and saved me a bunch of code that I was going to make.
The object is called UIAspectRatioConstraint, and once placed inside a GUI object, has many different settings. It would be unrequired to explain thoroughly, but you can choose which axis stays dominant, and the ratio you want. When I used it, I wanted an image to be square, so I set the ratio to be 1.
To keep the object in the middle of the screen, I find the best method is simply to do the following equation for the position:
UDim2.new(0.5-(ScaleX/2), -(OffsetX/2), 0.5-(ScaleY/2), -(OffsetY/2)
(if you only want the X to be in the middle, only utilize the first two, and vice versa.
If you have any questions, please do reply.
Hope this has helped :)