Home Reference Source Test
public class | source

Transform

Extends:

UpdateableComponent → Transform

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
Private Members
private
private
private
private

_scale: *

Method Summary

Public Methods
public

Triggers between two types of regularly used origin points.

public

flipX()

public

flipY()

public
public
public
public
public

rotate(rotation: number)

Adds the rotation parameter to the current Transform rotation.

public

scale(scaleX: number, scaleY: number, scaleZ: number)

Adds the parameters of this function to the Transforms scale.

public

Sets the origin offset position.

public

Sets the Transforms position.

public

setRotation(rotation: number)

Rotates the transform to face a different direction.

public

setScale(scaleX: number, scaleY: number, scaleZ: number)

public

Adds the parameters of this function to the Transforms position.

Inherited Summary

From class Updateable
public
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

Called when the object is intended to be paused.

public

Called when the the object is first introduced.

public

Called when the object is to be unpaused from paused state.

public

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

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
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#constructor

Public Members

public className: string source

Override:

Component#className

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:

NameTypeAttributeDescription
center boolean

"Center" if true, "Default" if false.

public flipX() source

public flipY() source

public getOriginOffset(): Point source

Return:

Point

The transform's origin offset.

public getPosition(): Point source

Return:

Point

The transform's position.

public getRotation(): number source

Return:

number

The transform's rotation.

public getScale(): Point source

Return:

Point

The transform's scale.

public rotate(rotation: number) source

Adds the rotation parameter to the current Transform rotation.

Params:

NameTypeAttributeDescription
rotation number

Rotation to add.

public scale(scaleX: number, scaleY: number, scaleZ: number) source

Adds the parameters of this function to the Transforms scale.

Params:

NameTypeAttributeDescription
scaleX number

X scale. Defaults to 0.

scaleY number

Y scale. Defaults to 0.

scaleZ number

Z scale. Defaults to 0.

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.

Params:

NameTypeAttributeDescription
x number

X axis offset. Defaults to current origin offset X.

y number

Y axis offset. Defaults to current origin offset Y.

z number

Z axis offset. Defaults to current origin offset Z.

public setPosition(x: number, y: number, z: number) source

Sets the Transforms position.

Params:

NameTypeAttributeDescription
x number

X position. Defaults to current X position.

y number

Y position. Defaults to current Y position.

z number

Z position. Defaults to current Z position.

public setRotation(rotation: number) source

Rotates the transform to face a different direction.

TODO: implement more than z axis rotation.

Params:

NameTypeAttributeDescription
rotation number

Rotation around the Z axis (in degrees).

public setScale(scaleX: number, scaleY: number, scaleZ: number) source

Params:

NameTypeAttributeDescription
scaleX number

X scale from 1. Defaults to current scale X.

scaleY number

Y scale from 1. Defaults to current scale Y.

scaleZ number

Z scale from 1. Defaults to current scale Z.

public translate(x: number, y: number, z: number) source

Adds the parameters of this function to the Transforms position.

Params:

NameTypeAttributeDescription
x number

X position. Defaults to 0.

y number

Y position. Defaults to 0.

z number

Z position. Defaults to 0.