Navigation
These archived docs are for Phaser 2.6.1 Phaser 3 docs can be found on newdocs.phaser.io.
Phaser CE docs can be found on the Phaser CE Documentation site.

Constructor

Phaser. Matrix

new Matrix(a, b, c, d, tx, ty)

The Matrix is a 3x3 matrix mostly used for display transforms within the renderer.

It is represented like so:

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

Parameters
Name Type Argument Default Description
a number <optional>
1

Horizontal scaling

b number <optional>
0

Horizontal skewing

c number <optional>
0

Vertical skewing

d number <optional>
1

Vertical scaling

tx number <optional>
0

Horizontal translation

ty number <optional>
0

Vertical translation

Source code: geom/Matrix.js (Line 26)

Public Properties

a : number

Default Value
  • 1
Source code: geom/Matrix.js (Line 39)

b : number

Default Value
  • 0
Source code: geom/Matrix.js (Line 45)

c : number

Default Value
  • 0
Source code: geom/Matrix.js (Line 51)

d : number

Default Value
  • 1
Source code: geom/Matrix.js (Line 57)

tx : number

Default Value
  • 0
Source code: geom/Matrix.js (Line 63)

ty : number

Default Value
  • 0
Source code: geom/Matrix.js (Line 69)

[readonly] type : number

The const type of this object.

Source code: geom/Matrix.js (Line 75)

Public Methods

append(matrix) → {Phaser.Matrix}

Appends the given Matrix to this Matrix.

Parameters
Name Type Description
matrix Phaser.Matrix

The matrix to append to this one.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 345)

apply(pos, newPos) → {Phaser.Point}

Get a new position with the current transformation applied.

Can be used to go from a childs coordinate space to the world coordinate space (e.g. rendering)

Parameters
Name Type Argument Description
pos Phaser.Point

The origin Point.

newPos Phaser.Point <optional>

The point that the new position is assigned to. This can be same as input point.

Returns

The new point, transformed through this matrix.

Source code: geom/Matrix.js (Line 233)

applyInverse(pos, newPos) → {Phaser.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 childs coordinate space. (e.g. input)

Parameters
Name Type Argument Description
pos Phaser.Point

The origin Point.

newPos Phaser.Point <optional>

The point that the new position is assigned to. This can be same as input point.

Returns

The new point, inverse transformed through this matrix.

Source code: geom/Matrix.js (Line 254)

clone(output) → {Phaser.Matrix}

Creates a new Matrix object based on the values of this Matrix. If you provide the output parameter the values of this Matrix will be copied over to it. If the output parameter is blank a new Matrix object will be created.

Parameters
Name Type Argument Description
output Phaser.Matrix <optional>

If provided the values of this Matrix will be copied to it, otherwise a new Matrix object is created.

Returns

A clone of this Matrix.

Source code: geom/Matrix.js (Line 128)

copyFrom(matrix) → {Phaser.Matrix}

Copies the properties from the given Matrix into this Matrix.

Parameters
Name Type Description
matrix Phaser.Matrix

The Matrix to copy from.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 172)

copyTo(matrix) → {Phaser.Matrix}

Copies the properties from this Matrix to the given Matrix.

Parameters
Name Type Description
matrix Phaser.Matrix

The Matrix to copy from.

Returns

The destination Matrix object.

Source code: geom/Matrix.js (Line 157)

fromArray(array) → {Phaser.Matrix}

Sets the values of this Matrix to the values in the given array.

The Array elements should be set 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 Array

The array to copy from.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 81)

identity() → {Phaser.Matrix}

Resets this Matrix to an identity (default) matrix.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 371)

rotate(angle) → {Phaser.Matrix}

Applies a rotation transformation to this matrix.

Parameters
Name Type Description
angle number

The angle to rotate by, given in radians.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 318)

scale(x, y) → {Phaser.Matrix}

Applies a scale transformation to this matrix.

Parameters
Name Type Description
x number

The amount to scale horizontally.

y number

The amount to scale vertically.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 297)

setTo(a, b, c, d, tx, ty) → {Phaser.Matrix}

Sets the values of this Matrix to the given values.

Parameters
Name Type Description
a number

Horizontal scaling

b number

Horizontal skewing

c number

Vertical skewing

d number

Vertical scaling

tx number

Horizontal translation

ty number

Vertical translation

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 103)

toArray(transpose, array) → {PIXI.Float32Array}

Creates a Float32 Array with values populated from this Matrix object.

Parameters
Name Type Argument Default Description
transpose boolean <optional>
false

Whether the values in the array are transposed or not.

array PIXI.Float32Array <optional>

If provided the values will be set into this array, otherwise a new Float32Array is created.

Returns
PIXI.Float32Array -

The newly created array which contains the matrix.

Source code: geom/Matrix.js (Line 192)

translate(x, y) → {Phaser.Matrix}

Translates the matrix on the x and y. This is the same as Matrix.tx += x.

Parameters
Name Type Description
x number

The x value to translate on.

y number

The y value to translate on.

Returns

This Matrix object.

Source code: geom/Matrix.js (Line 279)