TweenSizeAndPosition Guide

From Legacy Roblox Wiki
Jump to navigationJump to search

Introduction

What is TweenSizeAndPosition? TweenSizeAndPosition is a method of GuiObjects (such as Frame, TextButton etc..). It is used to efficiently and effectively gradually resize and re-position the given GuiObject after the given amount of time.

Arguments

The arguments of TweenSizeAndPosition are as followed;

endSize, endPosition, easingDirection, easingStyle, time, override, callback

(UDim2 endSize, UDim2 endPosition, EasingDirection easingDirection = Out, EasingStyle easingStyle = Quad, float time = 1, bool override = false, Function callback = nil)

How to use the method

Let's say we have a Frame in the parent of this script and your hierarchy looks like this;

  • StarterGui
    • ScreenGui
      • Frame
      • Script

And Frame's position might be set to 0.5, 0, 0.5, 0 and it's size could be set to 0, 0, 0, 0 and we want to make the frame zoom in from the middle of the screen. The problem is, if we just resized it then it wouldn't be in the middle of the screen.

The script would be;

script.Parent.Frame:TweenSizeAndPosition(UDim2.new(0, 100, 0, 200), UDim2.new(0.5, -50, 0.5, -100), "Out", "Quad", 1, false, nil)

The example above will resize the Frame to {0, 100}, {0, 200} and the position would become {0.5, -50}, {0.5, -100}, this would mean the Frame would stay in the middle of the screen. The "Out" argument is for the easingDirection, "Quad" is the easingStyle, 1 is the float time, false is the override and nil is for the callback.

See Also