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

Making Frame Close in on itself to center point?

Asked by 2 years ago

So I have a box frame and I'm trying to make it close within it's "True" center point.

local Main = script.Parent
local MapGui = Main:WaitForChild("MapGUI")

local offset = Vector3.new(0, 0, 5)

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quart, Enum.EasingDirection.InOut)
local CloseTween = TweenService:Create(MapGui, tweenInfo, {Size = UDim2.new(0,0,0,0)})
local OpenTween = TweenService:Create(MapGui, tweenInfo, {Size = UDim2.new(0.74, 0,0.814, 0)})

whenever I call the CloseTween function, it always zooms into the corner before disappearing, but I want it to zoom into the center as it disappears. Is that possible? I've tried to look it up but haven't found anything useful.

1 answer

Log in to vote
0
Answered by
Miniller 562 Moderation Voter
2 years ago

Set the AnchorPoint property of the frame to 0.5, 0.5.

Then, inside of the TweenService:Create function, you can use Position = UDim2.new() with the frame's coordinates

local scaleX = MapGui.Position.X.Scale
local scaleY = MapGui.Position.Y.Scale
local offsetX = MapGui.Position.X.Offset
local offsetY = MapGui.Position.Y.Offset

local CloseTween = TweenService:Create(MapGui, tweenInfo, {Size = UDim2.new(0,0,0,0), Position = UDim2.new(scaleX, offsetX, scaleY, offsetY)})
Ad

Answer this question