Transform

new Transform()

A Transform Component is responsible for the position, rotation and scale of an entity. Every entity component must have a transform component. Without a transform component, the entity will not be rendered.

Properties
NameTypeDefaultDescription
positionVector2Vector2.zero()

The position of the entity.

rotationnumber0

The rotation of the entity in degrees.

scaleVector2Vector2.one()

The scale of the entity.

Example
// Create a transform component
let transform = new Transform(new Vector2(0,0),0,new Vector2(1,1));

// Add the transform component to an entity
entity.AddComponent(transform);

Extends

Members

center

Center the UI element. Set/Get the x and y position of the UI element so that center of the UI element is as specified.

height

Height of the UI element.

position :Vector2

The vector representing the position of the entity.

Type:

(readonly) properties

The entity that this component is attached to.

Inherited From

rotation :number

Thr rotation of the entity.

Type:
  • number

rotation

Rotation of the UI element in degrees.

scale :Vector2

A Vector2 representing the scale of the entity. Scale defaults to Vector2.one(). Changing the scale will not affect the width, height and radius of the entity. Scale only affects the Rendering of the entity.

Type:

width :number

Width of the UI element.

Type:
  • number

x :number

X position of the UI element.

Type:
  • number

y :number

Y position of the UI element.

Type:
  • number

Methods

Align(mode)

Align the UI element to the parent as per the specified mode. If the UI element has no parent, it will align to the window.

Parameters:
NameTypeDefaultDescription
modestring"center"

The mode of alignment.

ModeDescription
"top"Align the UI element to the top of the parent.
"middle"Align the UI element to the middle of the parent.
"bottom"Align the UI element to the bottom of the parent.
"left"Align the UI element to the left of the parent.
"right"Align the UI element to the right of the parent.
"center"Align the UI element to the center of the parent.
Example
// Align the UI element to the top of the parent.
transform.align("top");

Fill(mode, padX, padY)

Fill the Entity with the parent as per the specified mode. If the UI element has no parent, it will fill the window.

Parameters:
NameTypeDefaultDescription
modestring"both"

The mode of filling.

ModeDescription
"both"Fill the UI element to the size of the parent.
"x"Fill the UI element to the width of the parent.
"y"Fill the UI element to the height of the parent.
padXnumber0

Padding in the x direction.

padYnumber0

Padding in the y direction.

Example
// Fill the UI element to the size of the parent.
this.entity.getComponent(UITransform).fill();

GetForward() → {Vector2}

Returns the forward vector of the entity.

Returns:

The forward vector of the entity.

Type: 
Vector2

IsClicked() → {boolean}

Check if the UI element is being clicked.

Returns:
  • True if the UI element is being clicked.
Type: 
boolean

IsHovered() → {boolean}

Check if the UI element is being hovered over.

Returns:
  • True if the UI element is being hovered over.
Type: 
boolean

Rotate(angle)

Rotates the entity by the given angle.

Parameters:
NameTypeDescription
anglenumber

The angle by which the entity is rotated.

Scale(scale)

Scales the entity by the given vector.

Parameters:
NameTypeDescription
scaleVector2

The vector by which the entity is scaled.

Translate(translation)

Translates the entity by the given vector.

Parameters:
NameTypeDescription
translationVector2

The vector by which the entity is translated.