# PIXI.Matrix

``class Matrix``

The PixiJS Matrix as a class makes it a lot faster.

Here is a representation of it:

``````| a | c | tx|
| b | d | ty|
| 0 | 0 | 1 |
``````

## Constructor

``new PIXI.Matrix(a: number, b: number, c: number, d: number, tx: number, ty: number) → {}``
Parameters:
Name Type Default Description
a number 1

x scale

b number 0

y skew

c number 0

x skew

d number 1

y scale

tx number 0

x translation

ty number 0

y translation

## Summary

### Properties from Matrix

 PIXI.Matrix static IDENTITY PIXI.Matrix static TEMP_MATRIX number a = 1 number b = 0 number c = 0 number d = 1 number tx = 0 number ty = 0

### Methods from Matrix

 this append(matrix: PIXI.Matrix) PIXI.Point apply(pos: IPointData, newPos: PIXI.Point) PIXI.Point applyInverse(pos: IPointData, newPos: PIXI.Point) PIXI.Matrix clone() PIXI.Matrix copyFrom(matrix: PIXI.Matrix) PIXI.Matrix copyTo(matrix: PIXI.Matrix) PIXI.Transform decompose(transform: PIXI.Transform) void fromArray(array: number[]) Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows: this identity() this invert() this prepend(matrix: PIXI.Matrix) this rotate(angle: number) this scale(x: number, y: number) this set(a: number, b: number, c: number, d: number, tx: number, ty: number) this setTransform(x: number, y: number, pivotX: number, pivotY: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number) Float32Array toArray(transpose: boolean, out: Float32Array) this translate(x: number, y: number)

## Public Properties

IDENTITY
``static IDENTITY: PIXI.Matrix``

A default (identity) matrix

TEMP_MATRIX
``static TEMP_MATRIX: PIXI.Matrix``

A temp matrix

a
``a: number = 1``
b
``b: number = 0``
c
``c: number = 0``
d
``d: number = 1``
tx
``tx: number = 0``
ty
``ty: number = 0``

## Public Methods

append
``append(matrix: PIXI.Matrix) → {this}``

Appends the given Matrix to this Matrix.

Parameters:
Name Type Description
matrix PIXI.Matrix

The matrix to append.

Returns:
Type Description
this

This matrix. Good for chaining method calls.

apply
``apply(pos: IPointData, newPos: PIXI.Point) → {PIXI.Point}``

Get a new position with the current transformation applied. Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)

Parameters:
Name Type Attributes Description
pos IPointData

The origin

newPos PIXI.Point

<optional>

The point that the new position is assigned to (allowed to be same as input)

Returns:
Type Description
PIXI.Point

The new point, transformed through this matrix

applyInverse
``applyInverse(pos: IPointData, newPos: PIXI.Point) → {PIXI.Point}``

Get a new position with the inverse of the current transformation applied. Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)

Parameters:
Name Type Attributes Description
pos IPointData

The origin

newPos PIXI.Point

<optional>

The point that the new position is assigned to (allowed to be same as input)

Returns:
Type Description
PIXI.Point

The new point, inverse-transformed through this matrix

clone
``clone() → {PIXI.Matrix}``

Creates a new Matrix object with the same values as this one.

Returns:
Type Description
PIXI.Matrix

A copy of this matrix. Good for chaining method calls.

copyFrom
``copyFrom(matrix: PIXI.Matrix) → {PIXI.Matrix}``

Changes the values of the matrix to be the same as the ones in given matrix

Parameters:
Name Type Description
matrix PIXI.Matrix

The matrix to copy from.

Returns:
Type Description
PIXI.Matrix

this

copyTo
``copyTo(matrix: PIXI.Matrix) → {PIXI.Matrix}``

Changes the values of the given matrix to be the same as the ones in this matrix

Parameters:
Name Type Description
matrix PIXI.Matrix

The matrix to copy to.

Returns:
Type Description
PIXI.Matrix

The matrix given in parameter with its values updated.

decompose
``decompose(transform: PIXI.Transform) → {PIXI.Transform}``

Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.

Parameters:
Name Type Description
transform PIXI.Transform

The transform to apply the properties to.

Returns:
Type Description
PIXI.Transform

The transform with the newly applied properties

fromArray
``fromArray(array: number[]) → {void}``

Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:

a = array[0] b = array[1] c = array[3] d = array[4] tx = array[2] ty = array[5]

Parameters:
Name Type Description
array number[]

The array that the matrix will be populated from.

Returns:
Type Description
void
identity
``identity() → {this}``

Resets this Matrix to an identity (default) matrix.

Returns:
Type Description
this

This matrix. Good for chaining method calls.

invert
``invert() → {this}``

Inverts this matrix

Returns:
Type Description
this

This matrix. Good for chaining method calls.

prepend
``prepend(matrix: PIXI.Matrix) → {this}``

Prepends the given Matrix to this Matrix.

Parameters:
Name Type Description
matrix PIXI.Matrix

The matrix to prepend

Returns:
Type Description
this

This matrix. Good for chaining method calls.

rotate
``rotate(angle: number) → {this}``

Applies a rotation transformation to the matrix.

Parameters:
Name Type Description
angle number

The angle in radians.

Returns:
Type Description
this

This matrix. Good for chaining method calls.

scale
``scale(x: number, y: number) → {this}``

Applies a scale transformation to the matrix.

Parameters:
Name Type Description
x number

The amount to scale horizontally

y number

The amount to scale vertically

Returns:
Type Description
this

This matrix. Good for chaining method calls.

set
``set(a: number, b: number, c: number, d: number, tx: number, ty: number) → {this}``

Sets the matrix properties.

Parameters:
Name Type Description
a number

Matrix component

b number

Matrix component

c number

Matrix component

d number

Matrix component

tx number

Matrix component

ty number

Matrix component

Returns:
Type Description
this

This matrix. Good for chaining method calls.

setTransform
``setTransform(x: number, y: number, pivotX: number, pivotY: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number) → {this}``

Sets the matrix based on all the available properties

Parameters:
Name Type Description
x number

Position on the x axis

y number

Position on the y axis

pivotX number

Pivot on the x axis

pivotY number

Pivot on the y axis

scaleX number

Scale on the x axis

scaleY number

Scale on the y axis

rotation number

skewX number

Skew on the x axis

skewY number

Skew on the y axis

Returns:
Type Description
this

This matrix. Good for chaining method calls.

toArray
``toArray(transpose: boolean, out: Float32Array) → {Float32Array}``

Creates an array from the current Matrix object.

Parameters:
Name Type Attributes Default Description
transpose boolean

Whether we need to transpose the matrix or not

out Float32Array

<optional>

new Float32Array(9)

If provided the array will be assigned to out

Returns:
Type Description
Float32Array

The newly created array which contains the matrix

translate
``translate(x: number, y: number) → {this}``

Translates the matrix on the x and y.

Parameters:
Name Type Description
x number

How much to translate x by

y number

How much to translate y by

Returns:
Type Description
this

This matrix. Good for chaining method calls.