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

Constructor

Phaser. Utils

new Utils()

Source code: utils/Utils.js (Line 11)

Classes

Debug

Public Methods

<static> extend(deep, target) → {object}

This is a slightly modified version of http://api.jquery.com/jQuery.extend/

Parameters
Name Type Description
deep boolean

Perform a deep copy?

target object

The target object to copy to.

Returns
object -

The extended object.

Source code: utils/Utils.js (Line 264)

<static> getProperty(obj, prop) → {*}

Gets an objects property by string.

Parameters
Name Type Description
obj object

The object to traverse.

prop string

The property whose value will be returned.

Returns
* -

the value of the property or null if property isn't found .

Source code: utils/Utils.js (Line 13)

<static> isPlainObject(obj) → {boolean}

This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].

Parameters
Name Type Description
obj object

The object to inspect.

Returns
boolean -
  • true if the object is plain, otherwise false.
Source code: utils/Utils.js (Line 228)

<static> mixin(from, to) → {object}

Mixes the source object into the destination object, returning the newly modified destination object. Based on original code by @mudcube

Parameters
Name Type Description
from object

The object to copy (the source object).

to object

The object to copy to (the destination object).

Returns
object -

The modified destination object.

Source code: utils/Utils.js (Line 395)

<static> mixinPrototype(target, mixin, replace)

Mixes in an existing mixin object with the target.

Values in the mixin that have either get or set functions are created as properties via defineProperty except if they also define a clone method - if a clone method is defined that is called instead and the result is assigned directly.

Parameters
Name Type Argument Default Description
target object

The target object to receive the new functions.

mixin object

The object to copy the functions from.

replace boolean <optional>
false

If the target object already has a matching function should it be overwritten or not?

Source code: utils/Utils.js (Line 343)

<static> pad(str, len, pad, dir) → {string}

Javascript string pad http://www.webtoolkit.info/.

Parameters
Name Type Argument Default Description
str string

The target string.

len number

The number of characters to be added.

pad number

The string to pad it out with (defaults to a space).

dir number <optional>
3

The direction dir = 1 (left), 2 (right), 3 (both).

Returns
string -

The padded string

Source code: utils/Utils.js (Line 186)

<static> parseDimension(size, dimension) → {number}

Get a unit dimension from a string.

Parameters
Name Type Description
size string | number

The size to parse.

dimension number

The window dimension to check.

Returns
number -

The parsed dimension.

Source code: utils/Utils.js (Line 143)

<static> rotateArray(matrix, direction) → {Array.<Array.<any>>}

This method is deprecated and should not be used. It may be removed in the future.

Rotates the given matrix (array of arrays).

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

Parameters
Name Type Description
matrix Array.<Array.<any>>

The array to rotate; this matrix may be altered.

direction number | string

The amount to rotate: the roation in degrees (90, -90, 270, -270, 180) or a string command ('rotateLeft', 'rotateRight' or 'rotate180').

Returns
Array.<Array.<any>> -

The rotated matrix. The source matrix should be discarded for the returned matrix.

Deprecated:
  • 2.2.0 - Use Phaser.ArrayUtils.rotateMatrix
Source code: utils/Utils.js (Line 116)

<static> setProperty(obj, prop) → {object}

Sets an objects property by string.

Parameters
Name Type Description
obj object

The object to traverse

prop string

The property whose value will be changed

Returns
object -

The object on which the property was set.

Source code: utils/Utils.js (Line 46)

<static> shuffle(array) → {Array.<any>}

This method is deprecated and should not be used. It may be removed in the future.

A standard Fisher-Yates Array shuffle implementation.

Parameters
Name Type Description
array Array.<any>

The array to shuffle.

Returns
Array.<any> -

The shuffled array.

Deprecated:
  • 2.2.0 - User Phaser.ArrayUtils.shuffle
Source code: utils/Utils.js (Line 131)

<static> transposeArray(array) → {Array.<Array.<any>>}

This method is deprecated and should not be used. It may be removed in the future.

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

Parameters
Name Type Description
array Array.<Array.<any>>

The matrix to transpose.

Returns
Array.<Array.<any>> -

A new transposed matrix

Deprecated:
  • 2.2.0 - Use Phaser.ArrayUtils.transposeMatrix
Source code: utils/Utils.js (Line 104)

randomChoice(choice1, choice2) → {any}

Choose between one of two values randomly.

Parameters
Name Type Description
choice1 any
choice2 any
Returns
any -

The randomly selected choice

Source code: utils/Utils.js (Line 92)