Namespace: Matrix

Phaser.Utils.Array. Matrix

Methods


<static> CheckMatrix(matrix)

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:

   [
       [ 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 Description
matrix array

The array to check.

Since: 3.0.0
Source: src/utils/array/matrix/CheckMatrix.js (Line 7)
Returns:

true if the given matrix array is a valid matrix.

Type
boolean

<static> MatrixToString(matrix)

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

Parameters:
Name Type Description
matrix array

A 2-dimensional array.

Since: 3.0.0
Source: src/utils/array/matrix/MatrixToString.js (Line 10)
Returns:

A string representing the matrix.

Type
string

<static> ReverseColumns(matrix)

Reverses the columns in the given Array Matrix.

Parameters:
Name Type Description
matrix array

The array matrix to reverse the columns for.

Since: 3.0.0
Source: src/utils/array/matrix/ReverseColumns.js (Line 7)
Returns:

The column reversed matrix.

Type
array

<static> ReverseRows(matrix)

Reverses the rows in the given Array Matrix.

Parameters:
Name Type Description
matrix array

The array matrix to reverse the rows for.

Since: 3.0.0
Source: src/utils/array/matrix/ReverseRows.js (Line 7)
Returns:

The column reversed matrix.

Type
array

<static> Rotate180(matrix)

Rotates the array matrix 180 degrees.

Parameters:
Name Type Description
matrix array

The array to rotate.

Since: 3.0.0
Source: src/utils/array/matrix/Rotate180.js (Line 9)
Returns:

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

Type
array

<static> RotateLeft(matrix)

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

Parameters:
Name Type Description
matrix array

The array to rotate.

Since: 3.0.0
Source: src/utils/array/matrix/RotateLeft.js (Line 9)
Returns:

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

Type
array

<static> RotateMatrix(matrix [, direction])

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

Parameters:
Name Type Argument Default Description
matrix array

The array to rotate.

direction number | string <optional>
90

The amount to rotate the matrix by.

Since: 3.0.0
Source: src/utils/array/matrix/RotateMatrix.js (Line 10)
Returns:

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

Type
array

<static> RotateRight(matrix)

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

Parameters:
Name Type Description
matrix array

The array to rotate.

Since: 3.0.0
Source: src/utils/array/matrix/RotateRight.js (Line 9)
Returns:

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

Type
array

<static> TransposeMatrix(array)

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.

Parameters:
Name Type Description
array array

The array matrix to transpose.

Since: 3.0.0
Source: src/utils/array/matrix/TransposeMatrix.js (Line 7)
Returns:

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

Type
array