Phaser.Utils.Array.Matrix
Scope: static
Static functions
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:
| name | type | optional | description |
|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The 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 formatted string representation of the given Array Matrix, suitable for logging to the console via console.log. Each row is rendered on its own line with cell values separated by |, and rows are divided by a ---+ separator line.
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:
| name | type | optional | description |
|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | A 2-dimensional array representing the matrix to convert. |
Returns: string - A formatted string representing the matrix, with columns separated by | and rows separated by ---+ divider lines. Returns an empty string if the matrix is invalid.
Source: src/utils/array/matrix/MatrixToString.js#L10
Since: 3.0.0
ReverseColumns
<static> ReverseColumns([matrix])
Description:
Reverses the row order of the given Array Matrix, which has the effect of reversing the sequence of values within each column from top to bottom.
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:
| name | type | optional | description |
|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array matrix whose row order will be reversed. |
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 order of elements in each row of 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:
| name | type | optional | description |
|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array matrix to reverse the elements of each row for. |
Returns: Array.<Array.<T>> - The matrix with each row's elements reversed in place.
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:
| name | type | optional | description |
|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array to rotate. |
Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discarded 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 (counter-clockwise) by 90 degrees per step.
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:
| name | type | optional | default | description |
|---|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array to rotate. | |
| amount | number | Yes | 1 | The number of times to rotate the matrix 90 degrees to the left. |
Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discarded 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, 180 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:
| name | type | optional | default | description |
|---|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array to rotate. | |
| direction | number | string | Yes | 90 | The amount to rotate the matrix by. Must be a degree value of 90, -90, 270, -270, 180 or -180, or a string command of rotateLeft, rotateRight or rotate180. If an unrecognized value is given the matrix will not be rotated. |
Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discarded 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 90 degrees to the right (clockwise).
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:
| name | type | optional | default | description |
|---|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array to rotate. | |
| amount | number | Yes | 1 | The number of times to rotate the matrix 90 degrees clockwise. |
Returns: Array.<Array.<T>> - The rotated matrix array. The source matrix should be discarded 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 its rows and the elements within each row by the amounts specified. The translation wraps cyclically: elements shifted off one edge of the matrix reappear on the opposite edge.
A positive x value shifts elements within each row to the right, and a negative value shifts them to the left. A positive y value shifts rows downward, and a negative value shifts them upward.
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:
| name | type | optional | default | description |
|---|---|---|---|---|
| matrix | Array.<Array.<T>> | Yes | The array matrix to translate. | |
| x | number | Yes | 0 | The amount to horizontally translate the matrix by. |
| y | number | Yes | 0 | The 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 one row. 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:
| name | type | optional | description |
|---|---|---|---|
| array | Array.<Array.<T>> | Yes | The 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