Udim2

Overview

Description

UDim2 is a data type used in Roblox to define the size and position of UI elements. This value is calculated based on scale (fraction) and offset (pixel size). UDim2 is composed of two axes (X and Y) and is commonly used to set the size and position of UI elements in a flexible manner.

Properties

X

UDim Specifies the value for the X-axis. This value consists of two parts (scale and offset) that determine the size or position of a UI element using a combination of proportion and specific pixel sizes.

Code Samples

-- Example using the X property
local udim2_value = UDim2.new(0.5, 10, 0, 0)
print(udim2_value.X) -- Output: 0.5 (Scale), 10 (Offset)

Y

UDim Specifies the value for the Y-axis. Similar to the X property, it uses scale and offset to determine the vertical size or position of a UI element.

Code Samples

-- Example using the Y property
local udim2_value = UDim2.new(0, 0, 1, -20)
print(udim2_value.Y) -- Output: 1 (Scale), -20 (Offset)

Constructors

new

UDim2.new is a constructor that creates a UDim2 object. It allows you to specify the scale and offset values for both the X and Y axes in detail to define the object.

Parameters

number xScale

X-axis scale

number xOffset

X-axis offset

number yScale

Y-axis scale

number yOffset

Y-axis offset

Return

UDim2

The newly created UDim2 object

Code Samples

-- Creating a new UDim2 object
local position = UDim2.new(0.5, 10, 0.5, 20)

-- Applying to the Position property
ui_element.Position = position

Methods

Last updated