Resize a frame keeping its original position

Title, i dont know how to explain this better, just apply size to both sides of a frame equally so the center point stays the same, instead of the center point going where the frame is being resized

Does this work?

local function resizeWithoutMovingCenter(frame: Frame, newSize: Udim2): ()
	local sizeAddition: Udim2 = newSize - frame.Size
	local posAddition: Udim2 = Udim2.new(-.5 * sizeAddition.X.Scale, -.5 * sizeAddition.X.Offset, -.5 * sizeAddition.Y.Scale, -.5 * sizeAddition.Y.Offset)
	frame.Size = newSize
	frame.Position += posAddition
end

The other option is setting

Frame.AnchorPoint = Vector2.new(.5, .5)

but then you’d also have to set the position differently.

yeah that seems to work, thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.