Transform
Extends:
A component all GameObjects are given by default on instantiation.
Transform components are unique to the object, meaning there cannot be more than one Transform on a GameObject.
Transforms keep track of GameObject position, scale (size), rotation, and origin offset. These should be changes with their respective setters, and not directly, to ensure the correct components are notified of these changes.
TODO: Make rotation work on 3 axis like position and scale. TODO: Change the updates and setters of the position/scale/rotation to use funcions in their base definitions and remove the wrappers here to reduce code.
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
|
|
public |
renderable: * |
Private Members | ||
private |
|
|
private |
_position: * |
|
private |
_rotation: * |
|
private |
_scale: * |
Method Summary
Public Methods | ||
public |
centerOrigin(center: boolean) Triggers between two types of regularly used origin points. |
|
public |
flipX() |
|
public |
flipY() |
|
public |
|
|
public |
getPosition(): Point |
|
public |
|
|
public |
|
|
public |
Adds the rotation parameter to the current Transform rotation. |
|
public |
Adds the parameters of this function to the Transforms scale. |
|
public |
setOriginOffset(x: number, y: number, z: number) Sets the origin offset position. |
|
public |
setPosition(x: number, y: number, z: number) Sets the Transforms position. |
|
public |
setRotation(rotation: number) Rotates the transform to face a different direction. |
|
public |
|
|
public |
Adds the parameters of this function to the Transforms position. |
Inherited Summary
From class Updateable | ||
public |
deregister: * |
|
public |
|
|
public |
|
|
public |
id: * |
|
public |
Cleanup code for when destroying an Updateable. |
|
public |
end() Base call function for when this Updateable is to be ended. |
|
public |
onEnd() Called when the object is being removed or cleaned up from usage. |
|
public |
onPause() Called when the object is intended to be paused. |
|
public |
onStart() Called when the the object is first introduced. |
|
public |
Called when the object is to be unpaused from paused state. |
|
public |
onUpdate() Called on every update within the game, once the object has had onStart called. |
|
public |
pause() Base call function for when this Updateable is to be paused. |
|
public |
start() Base call function for when this Updateable is to be started. |
|
public |
unpause() Base call function for when this Updateable is to be unpaused. |
|
public |
update() Base call function for when this Updateable is to be updated. |
From class Component | ||
public |
|
|
public |
isUnique: * |
|
public |
Called when the component is successfully added to a GameObject. |
Public Constructors
public constructor() source
Constructor for Base Components. Requires a boolean to indicate if a GameObject can contain multiple components of this type.
Override:
Component#constructorPublic Members
public renderable: * source
Private Members
private _originOffset: * source
private _position: * source
private _rotation: * source
private _scale: * source
Public Methods
public centerOrigin(center: boolean) source
Triggers between two types of regularly used origin points.
Origin points are used with Renderables and other components to offset the origin different from the Transform's position.
"Center": (-0.5, -0.5, -0.5) centered to the Tranform's position, and "Default": (0, 0, 0), beginning at the top left of the Transform.
Params:
Name | Type | Attribute | Description |
center | boolean | "Center" if true, "Default" if false. |
public flipX() source
public flipY() source
public rotate(rotation: number) source
Adds the rotation parameter to the current Transform rotation.
Params:
Name | Type | Attribute | Description |
rotation | number | Rotation to add. |
public scale(scaleX: number, scaleY: number, scaleZ: number) source
Adds the parameters of this function to the Transforms scale.
public setOriginOffset(x: number, y: number, z: number) source
Sets the origin offset position.
If you want an object to exist at a position, but do something else (like drawing, animations) in a relative position the the Tranform, use this to change the offset from the Transfrom.
(0, 0, 0) would be top left of the transform. (-0.5, -0.5, -0.5) would be center of the transform. (-1, -1, -1) would be bottom right of transform.
Parameters default to their current values.
public setRotation(rotation: number) source
Rotates the transform to face a different direction.
TODO: implement more than z axis rotation.
Params:
Name | Type | Attribute | Description |
rotation | number | Rotation around the Z axis (in degrees). |