Skip to main content

Transform

Description:

  Object containing a coordinate system transformation.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Transform): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Transform, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Transform): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

clone

Type: Function.

Description:

  Creates a new copy of this Transform.

Signature:

clone: function(self: Transform): Transform

Returns:

Return TypeDescription
TransformThe copy of this Transform.

inverse

Type: Function.

Description:

  Creates a new Transform containing the inverse of this Transform.

Signature:

inverse: function(self: Transform): Transform

Returns:

Return TypeDescription
TransformA new Transform object representing the inverse of this Transform's matrix.

apply

Type: Function.

Description:

  Applies the given other Transform object to this one. This effectively multiplies this Transform's internal transformation matrix with the other Transform's (i.e. self

  • other), and stores the result in this object.

Signature:

apply: function(self: Transform, other: Transform): Transform

Parameters:

ParameterTypeDescription
otherTransformThe other Transform object to apply to this Transform.

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

isAffine2DTransform

Type: Function.

Description:

  Checks whether the Transform is an affine transformation.

Signature:

isAffine2DTransform: function(self: Transform): boolean

Returns:

Return TypeDescription
booleantrue if the transform object is an affine transformation, false otherwise.

translate

Type: Function.

Description:

  Applies a translation to the Transform's coordinate system. This method does not reset any previously applied transformations.

Signature:

translate: function(self: Transform, x: number, y: number): Transform

Parameters:

ParameterTypeDescription
xnumberThe relative translation along the x-axis.
ynumberThe relative translation along the y-axis.

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

rotate

Type: Function.

Description:

  Applies a rotation to the Transform's coordinate system. This method does not reset any previously applied transformations.

Signature:

rotate: function(self: Transform, angle: number): Transform

Parameters:

ParameterTypeDescription
anglenumberThe relative angle in radians to rotate this Transform by.

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

scale

Type: Function.

Description:

  Scales the Transform's coordinate system. This method does not reset any previously applied transformations.

Signature:

scale: function(self: Transform, x: number, y?: number): Transform

Parameters:

ParameterTypeDescription
xnumberThe relative scale factor along the x-axis.
ynumberThe relative scale factor along the y-axis. (Default: sx.)

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

shear

Type: Function.

Description:

  Applies a shear factor (skew) to the Transform's coordinate system. This method does not reset any previously applied transformations.

Signature:

shear: function(self: Transform, x: number, y: number): Transform

Parameters:

ParameterTypeDescription
xnumberThe shear factor along the x-axis.
ynumberThe shear factor along the y-axis.

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

reset

Type: Function.

Description:

  Resets the Transform to an identity state. All previously applied transformations are erased.

Signature:

reset: function(self: Transform): Transform

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

setTransformation

Type: Function.

Description:

  Resets the Transform to the specified transformation parameters.

Signature:

setTransformation: function(self: Transform, x?: number, y?: number, angle?: number, scale_x?: number, scale_y?: number, origin_x?: number, origin_y?: number, shear_x?: number, shear_y?: number): Transform

Parameters:

ParameterTypeDescription
xnumberThe position of the Transform on the x-axis.
ynumberThe position of the Transform on the y-axis.
anglenumberThe orientation of the Transform in radians. (Default: 0.)
scale_xnumberScale factor on the x-axis. (Default: 1.)
scale_ynumberScale factor on the y-axis. (Default: sx.)
origin_xnumberOrigin offset on the x-axis. (Default: 0.)
origin_ynumberOrigin offset on the y-axis. (Default: 0.)
shear_xnumberShearing / skew factor on the x-axis. (Default: 0.)
shear_ynumberShearing / skew factor on the y-axis. (Default: 0.)

Returns:

Return TypeDescription
TransformThe Transform object the method was called on. Allows easily chaining Transform methods.

setMatrix

Type: Function.

Description:

  Directly sets the Transform's internal 4x4 transformation matrix.

Signature:

setMatrix: function(self: Transform, layout: string, elements: {number} | {{number}}): Transform

Parameters:

ParameterTypeDescription
layoutstringHow to interpret the matrix element arguments (row-major or column-major).
elements{number}{{number}}

Returns:

Return TypeDescription
Transformtransform — The Transform object the method was called on. Allows easily chaining Transform methods.

setMatrix

Type: Function.

Description:

  Directly sets the Transform's internal 4x4 transformation matrix.

Signature:

setMatrix: function(self: Transform, elements: {number} | {{number}}): Transform

Parameters:

ParameterTypeDescription
elements{number}{{number}}

Returns:

Return TypeDescription
Transformtransform — The Transform object the method was called on. Allows easily chaining Transform methods.

getMatrix

Type: Function.

Description:

  Gets the internal 4x4 transformation matrix stored by this Transform. The matrix is returned in row-major order.

Signature:

getMatrix: function(self: Transform): number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number

Returns:

Return TypeDescription
numberThe first column of the first row of the matrix.
numberThe second column of the first row of the matrix.
numberThe third column of the first row of the matrix.
numberThe fourth column of the first row of the matrix.
numberThe first column of the second row of the matrix.
numberThe second column of the second row of the matrix.
numberThe third column of the second row of the matrix.
numberThe fourth column of the second row of the matrix.
numberThe first column of the third row of the matrix.
numberThe second column of the third row of the matrix.
numberThe third column of the third row of the matrix.
numberThe fourth column of the third row of the matrix.
numberThe first column of the fourth row of the matrix.
numberThe second column of the fourth row of the matrix.
numberThe third column of the fourth row of the matrix.
numberThe fourth column of the fourth row of the matrix.

transformPoint

Type: Function.

Description:

  Applies the Transform object's transformation to the given 2D position. This effectively converts the given position from global coordinates into the local coordinate space of the Transform.

Signature:

transformPoint: function(self: Transform, x: number, y: number): number, number

Parameters:

ParameterTypeDescription
xnumberThe x component of the position in global coordinates.
ynumberThe y component of the position in global coordinates.

Returns:

Return TypeDescription
numberThe x component of the position with the transform applied.
numberThe y component of the position with the transform applied.

inverseTransformPoint

Type: Function.

Description:

  Applies the reverse of the Transform object's transformation to the given 2D position. This effectively converts the given position from the local coordinate space of the Transform into global coordinates. One use of this method can be to convert a screen-space mouse position into global world coordinates, if the given Transform has transformations applied that are used for a camera system in-game.

Signature:

inverseTransformPoint: function(self: Transform, x: number, y: number): number, number

Parameters:

ParameterTypeDescription
xnumberThe x component of the position with the transform applied.
ynumberThe y component of the position with the transform applied.

Returns:

Return TypeDescription
numberThe x component of the position in global coordinates.
numberThe y component of the position in global coordinates.