Phaser.Utils.Array.Matrix

Scope: static

Source: src/utils/array/matrix/index.js#L7

Methods:

Public Members

CheckMatrix

<static> CheckMatrix([matrix])

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. 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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
matrixArray.<Array.<T>>YesThe array to check.

Returns: boolean - true if the given matrix array is a valid matrix.

Source: src/utils/array/matrix/CheckMatrix.js#L7
Since: 3.0.0


MatrixToString

<static> MatrixToString([matrix])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
matrixArray.<Array.<T>>YesA 2-dimensional array.

Returns: string - A string representing the matrix.

Source: src/utils/array/matrix/MatrixToString.js#L10
Since: 3.0.0


ReverseColumns

<static> ReverseColumns([matrix])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
matrixArray.<Array.<T>>YesThe array matrix to reverse the columns for.

Returns: Array.<Array.<T>> - The column reversed matrix.

Source: src/utils/array/matrix/ReverseColumns.js#L7
Since: 3.0.0


ReverseRows

<static> ReverseRows([matrix])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
matrixArray.<Array.<T>>YesThe array matrix to reverse the rows for.

Returns: Array.<Array.<T>> - The column reversed matrix.

Source: src/utils/array/matrix/ReverseRows.js#L7
Since: 3.0.0


Rotate180

<static> Rotate180([matrix])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
matrixArray.<Array.<T>>YesThe array to rotate.

Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discard for the returned matrix.

Source: src/utils/array/matrix/Rotate180.js#L9
Since: 3.0.0


RotateLeft

<static> RotateLeft([matrix], [amount])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldefaultdescription
matrixArray.<Array.<T>>YesThe array to rotate.
amountnumberYes1The number of times to rotate the matrix.

Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discard for the returned matrix.

Source: src/utils/array/matrix/RotateLeft.js#L9
Since: 3.0.0


RotateMatrix

<static> RotateMatrix([matrix], [direction])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldefaultdescription
matrixArray.<Array.<T>>YesThe array to rotate.
directionnumber | stringYes90The amount to rotate the matrix by.

Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discard for the returned matrix.

Source: src/utils/array/matrix/RotateMatrix.js#L10
Since: 3.0.0


RotateRight

<static> RotateRight([matrix], [amount])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldefaultdescription
matrixArray.<Array.<T>>YesThe array to rotate.
amountnumberYes1The number of times to rotate the matrix.

Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discard for the returned matrix.

Source: src/utils/array/matrix/RotateRight.js#L9
Since: 3.0.0


Translate

<static> Translate([matrix], [x], [y])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldefaultdescription
matrixArray.<Array.<T>>YesThe array matrix to translate.
xnumberYes0The amount to horizontally translate the matrix by.
ynumberYes0The amount to vertically translate the matrix by.

Returns: Array.<Array.<T>> - The translated matrix.

Source: src/utils/array/matrix/TranslateMatrix.js#L10
Since: 3.50.0


TransposeMatrix

<static> TransposeMatrix([array])

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 ]
]

Tags:

  • generic
  • genericUse

Parameters:

nametypeoptionaldescription
arrayArray.<Array.<T>>YesThe array matrix to transpose.

Returns: Array.<Array.<T>> - A new array matrix which is a transposed version of the given array.

Source: src/utils/array/matrix/TransposeMatrix.js#L7
Since: 3.0.0


Private Members

Updated on