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.
Name | Type | Default | Description |
---|---|---|---|
position | Vector2 | Vector2.zero() | The position of the entity. |
rotation | number | 0 | The rotation of the entity in degrees. |
scale | Vector2 | Vector2.one() | The scale of the entity. |
- Source
// 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.
- Source
height
Height of the UI element.
- Source
position :Vector2
The vector representing the position of the entity.
- Source
(readonly) properties
The entity that this component is attached to.
- Inherited From
- Source
rotation :number
Thr rotation of the entity.
- number
- Source
rotation
Rotation of the UI element in degrees.
- Source
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.
- Source
width :number
Width of the UI element.
- number
- Source
x :number
X position of the UI element.
- number
- Source
y :number
Y position of the UI element.
- number
- Source
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.
Name | Type | Default | Description | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
mode | string | "center" | The mode of alignment.
|
- Source
// 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.
Name | Type | Default | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
mode | string | "both" | The mode of filling.
| ||||||||
padX | number | 0 | Padding in the x direction. | ||||||||
padY | number | 0 | Padding in the y direction. |
- Source
// Fill the UI element to the size of the parent.
this.entity.getComponent(UITransform).fill();
GetForward() → {Vector2}
Returns the forward vector of the entity.
- Source
The forward vector of the entity.
- Type:
- Vector2
IsClicked() → {boolean}
Check if the UI element is being clicked.
- Source
- True if the UI element is being clicked.
- Type:
- boolean
IsHovered() → {boolean}
Check if the UI element is being hovered over.
- Source
- True if the UI element is being hovered over.
- Type:
- boolean
Rotate(angle)
Rotates the entity by the given angle.
Name | Type | Description |
---|---|---|
angle | number | The angle by which the entity is rotated. |
- Source
Scale(scale)
Scales the entity by the given vector.
Name | Type | Description |
---|---|---|
scale | Vector2 | The vector by which the entity is scaled. |
- Source
Translate(translation)
Translates the entity by the given vector.
Name | Type | Description |
---|---|---|
translation | Vector2 | The vector by which the entity is translated. |
- Source