Phaser . ArrayUtils

new ArrayUtils ()

Utility functions for dealing with Arrays. 用于处理数组的实用函数。

Source - utils/ArrayUtils.js , line 13

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 Array.<number>

The input array which must be sorted.

Returns:
number -

The nearest value found.

Source - utils/ArrayUtils.js , line 172

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

Fetch a random entry from the given array.

Will return null if there are no array items that fall within the specified range or if there is no item for the randomly chosen index.

从给定数组中提取随机项。
如果没有属于指定范围的数组项或随机选择的索引没有项,则返回空。
Parameters:
Name Type Description
objects Array.<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. 阵列前面的可选偏移量。默认值为0,或 数组的开头。

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 27

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

Removes a random object from the given array and returns it. 从给定数组中移除随机对象并返回它。

Will return null if there are no array items that fall within the specified range or if there is no item for the randomly chosen index. 如果没有数组项属于指定的
范围或如果随机选择的索引没有项目。

Parameters:
Name Type Description
objects Array.<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. 阵列前面的可选偏移量。默认值为0,或 数组的开头。

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 51

<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 Array.<any>

The array to shift/rotate. The array is modified. 要移动/旋转的数组。数组已修改。

Returns:
any -

The shifted value.

Source - utils/ArrayUtils.js , line 195

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

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

Source - utils/ArrayUtils.js , line 132

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

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

Parameters:
Name Type Description
array Array.<any>

The array to shuffle.

Returns:
Array.<any> -

The original array, now shuffled.

Source - utils/ArrayUtils.js , line 80

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

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

Source - utils/ArrayUtils.js , line 101

numberArray (start, end) → {Array.<number>}

Create an array representing the inclusive range of numbers (usually integers) in [start, end] . This is equivalent to numberArrayStep(start, end, 1) .

Parameters:
Name Type Description
start number

The minimum value the array starts with.

end number

The maximum value the array contains.

Returns:
Array.<number> -

The array of number values.

Source - utils/ArrayUtils.js , line 212

numberArrayStep (start, end , step ) → {Array}

Create an array of numbers (positive and/or negative) progressing from start up to but not including end by advancing by step .

If start is less than end a zero-length range is created unless a negative step is specified.

Certain values for start and end (eg. NaN/undefined/null) are currently coerced to 0; for forward compatibility make sure to pass in actual numbers.

Parameters:
Name Type Argument Default Description
start number

The start of the range.

end number <optional>

The end of the range.

step number <optional>
1

The value to increment or decrement by.

Returns:
Array -

Returns the new array of numbers.

Source - utils/ArrayUtils.js , line 234
Example
                      Phaser.ArrayUtils.numberArrayStep(4); // => [0, 1, 2, 3] Phaser.ArrayUtils.numberArrayStep(1,
                      5); // => [1, 2, 3, 4] Phaser.ArrayUtils.numberArrayStep(0, 20, 5); //
                      => [0, 5, 10, 15] Phaser.ArrayUtils.numberArrayStep(0, -4, -1); // => [0,
                      -1, -2, -3] Phaser.ArrayUtils.numberArrayStep(1, 4, 0); // => [1, 1, 1]
                      Phaser.ArrayUtils.numberArrayStep(0); // => []
                    
Phaser Copyright © 2012-2015 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.2 on Thu Feb 18 2016 14:40:58 GMT+0000 (GMT Standard Time) using the DocStrap template .