Class: ArrayUtils

Phaser. ArrayUtils

new ArrayUtils()

Utility functions for dealing with Arrays.

Source - utils/ArrayUtils.js, line 3

Methods

<static> findClosest(value, arr) → {number}

Snaps a value to the nearest value in an array. The result will always be in the range [first_value, last_value].

Parameters:
Name Type Description
value number

The search value

arr number[]

The input array which must be sorted.

Returns:
number -

The nearest value found.

Source - utils/ArrayUtils.js, line 166

<static> getRandomItem(objects, startIndex, length) → {object}

Fetch a random entry from the given array. Will return null if random selection is missing, or array has no entries.

Parameters:
Name Type Description
objects any[]

An array of objects.

startIndex integer

Optional offset off the front of the array. Default value is 0, or the beginning of the array.

length integer

Optional restriction on the number of values you want to randomly select from.

Returns:
object -

The random object that was selected.

Source - utils/ArrayUtils.js, line 25

<static> removeRandomItem(objects, startIndex, length) → {object}

Removes a random object from the given array and returns it. Will return null if random selection is missing, or array has no entries.

Parameters:
Name Type Description
objects any[]

An array of objects.

startIndex integer

Optional offset off the front of the array. Default value is 0, or the beginning of the array.

length integer

Optional restriction on the number of values you want to randomly select from.

Returns:
object -

The random object that was removed.

Source - utils/ArrayUtils.js, line 49

<static> rotate(array) → {any}

Moves the element from the start of the array to the end, shifting all items in the process. The "rotation" happens to the left.

Parameters:
Name Type Description
array any[]

The array to shift/rotate. The array is modified.

Returns:
any -

The shifted value.

Source - utils/ArrayUtils.js, line 189

<static> rotateMatrix(matrix, direction) → {array}

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

Parameters:
Name Type Description
matrix array

The array to rotate.

direction number | string

The amount to rotate. Either a number: 90, -90, 270, -270, 180 or a string: 'rotateLeft', 'rotateRight' or 'rotate180'

Returns:
array -

The rotated array

Source - utils/ArrayUtils.js, line 126

<static> shuffle(array) → {array}

A standard Fisher-Yates Array shuffle implementation which modifies the array in place.

Parameters:
Name Type Description
array array

The array to shuffle.

Returns:
array -

The original array, now shuffled.

Source - utils/ArrayUtils.js, line 78

<static> transposeMatrix(array) → {array}

Transposes the elements of the given Array.

Parameters:
Name Type Description
array array

The array to transpose.

Returns:
array -

The transposed array.

Source - utils/ArrayUtils.js, line 99
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Nov 15 2014 19:54:29 GMT-0000 (GMT) using the DocStrap template.