Phaser API Documentation

  Version: 
Filter
Namespace: Matrix
Phaser.Utils.Array.Matrix

Methods

<static> CheckMatrix([matrix])
Focus
Focus

Description:

Checks if an array can be used as a matrix.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array to check.

Returns:
Description:

true if the given matrix array is a valid matrix.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> MatrixToString([matrix])
Focus
Focus

Description:

Generates a string (which you can pass to console.log) from the given Array Matrix.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

A 2-dimensional array.

Returns:
Description:

A string representing the matrix.

Type:
  • string
Since: 3.0.0
Focus
Focus
<static> ReverseColumns([matrix])
Focus
Focus

Description:

Reverses the columns in the given Array Matrix.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array matrix to reverse the columns for.

Returns:
Description:

The column reversed matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> ReverseRows([matrix])
Focus
Focus

Description:

Reverses the rows in the given Array Matrix.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array matrix to reverse the rows for.

Returns:
Description:

The column reversed matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> Rotate180([matrix])
Focus
Focus

Description:

Rotates the array matrix 180 degrees.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array to rotate.

Returns:
Description:

The rotated matrix array. The source matrix should be discard for the returned matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> RotateLeft([matrix])
Focus
Focus

Description:

Rotates the array matrix to the left (or 90 degrees)

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array to rotate.

Returns:
Description:

The rotated matrix array. The source matrix should be discard for the returned matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> RotateMatrix([matrix], [direction])
Focus
Focus

Description:

Rotates the array matrix based on the given rotation value.

The value can be given in degrees: 90, -90, 270, -270 or 180, or a string command: rotateLeft, rotateRight or rotate180.

Based on the routine from http://jsfiddle.net/MrPolywhirl/NH42z/.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments Default description
matrix Array.<Array.<T>> <optional>

The array to rotate.

direction number | string <optional> 90

The amount to rotate the matrix by.

Returns:
Description:

The rotated matrix array. The source matrix should be discard for the returned matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> RotateRight([matrix])
Focus
Focus

Description:

Rotates the array matrix to the left (or -90 degrees)

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array to rotate.

Returns:
Description:

The rotated matrix array. The source matrix should be discard for the returned matrix.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus
<static> Translate([matrix], [x], [y])
Focus
Focus

Description:

Translates the given Array Matrix by shifting each column and row the amount specified.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
matrix Array.<Array.<T>> <optional>

The array matrix to translate.

x number <optional>

The amount to horizontally translate the matrix by.

y number <optional>

The amount to vertically translate the matrix by.

Returns:
Description:

The translated matrix.

Type:
  • Array.<Array.<T>>
Since: 3.50.0
Focus
Focus
<static> TransposeMatrix([array])
Focus
Focus

Description:

Transposes the elements of the given matrix (array of arrays).

The transpose of a matrix is a new matrix whose rows are the columns of the original.

A matrix is a two-dimensional array (array of arrays), where all sub-arrays (rows) have the same length. There must be at least two rows. This is an example matrix:

[
   [ 1, 1, 1, 1, 1, 1 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 2, 0, 1, 2, 0, 4 ],
   [ 2, 0, 3, 4, 0, 4 ],
   [ 2, 0, 0, 0, 0, 4 ],
   [ 3, 3, 3, 3, 3, 3 ]
]

Parameters:

name type arguments description
array Array.<Array.<T>> <optional>

The array matrix to transpose.

Returns:
Description:

A new array matrix which is a transposed version of the given array.

Type:
  • Array.<Array.<T>>
Since: 3.0.0
Focus
Focus