Udim2

Overview

UDim2 is a data type that handles values in both horizontal (X) and vertical (Y) directions. For each direction, it includes both the scale value proportional to the entire size and fixed offset correction value in pixel. It is mostly used when flexibly specifying the size or position of UI elements on the screen.

Constructors

new

Creates a single UDim2 object based on the passed scale value for X axis and Y axis, and returns it. The created UDim2 can be used to manually specify the position or size of UI.

Parameters

number xScale

The scale value applied along the X axis relative to the size of parent.

number xOffset

The absolute value applied along the X axis in pixel.

number yScale

The scale value applied along the Y axis relative to the size of parent.

number yOffset

The absolute value applied along the Y axis in pixel.

Return

UDim2

The UDim2 consisted of the specified scale and offset values.

Code Samples

local Position = UDim2.new(0.5, 10, 0.5, 20)

TextLabel.Position = Position

Properties

X

It represents both the relative scale value and offset value in pixel applied along the X axis.

Code Samples

Y

It represents both the relative scale value and offset value in pixel applied along the Y axis.

Code Samples

Methods

Lerp

Returns a new Dim2 calculated by linearly interpolating between the current Dim2 and the target Dim2 according to the alpha ratio.

Parameters

UDim2 goal

The target UDim2 to be interpolated.

number alpha

A value indicating interpolation ratio.

Return

UDim2

The created UDim2.

Code Samples

See also

Coordinate Systemchevron-right

Last updated