You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Removes a random object from the given array and returns it.
41
-
* Will return null if random selection is missing, or array has no entries.
43
+
*
44
+
* Will return null if there are no array items that fall within the specified range
45
+
* or if there is no item for the randomly choosen index.
42
46
*
43
47
* @method
44
48
* @param {any[]} objects - An array of objects.
@@ -59,7 +63,7 @@ Phaser.ArrayUtils = {
59
63
if(randomIndex<objects.length)
60
64
{
61
65
varremoved=objects.splice(randomIndex,1);
62
-
returnremoved[0];
66
+
returnremoved[0]===undefined ? null : removed[0];
63
67
}
64
68
else
65
69
{
@@ -90,21 +94,24 @@ Phaser.ArrayUtils = {
90
94
},
91
95
92
96
/**
93
-
* Transposes the elements of the given Array.
97
+
* Transposes the elements of the given matrix (array of arrays).
94
98
*
95
99
* @method
96
-
* @param {array[]} array - The array to transpose.
97
-
* @return {array[]} The transposed array.
100
+
* @param {Array<any[]>} array - The matrix to transpose.
101
+
* @return {Array<any[]>} A new transposed matrix
98
102
*/
99
103
transposeMatrix: function(array){
100
104
101
-
varresult=newArray(array[0].length);
105
+
varsourceRowCount=array.length;
106
+
varsourceColCount=array[0].length;
102
107
103
-
for(vari=0;i<array[0].length;i++)
108
+
varresult=newArray(sourceColCount);
109
+
110
+
for(vari=0;i<sourceColCount;i++)
104
111
{
105
-
result[i]=newArray(array.length-1);
112
+
result[i]=newArray(sourceRowCount);
106
113
107
-
for(varj=array.length-1;j>-1;j--)
114
+
for(varj=sourceRowCount-1;j>-1;j--)
108
115
{
109
116
result[i][j]=array[j][i];
110
117
}
@@ -115,13 +122,14 @@ Phaser.ArrayUtils = {
115
122
},
116
123
117
124
/**
118
-
* Rotates the given array.
119
-
* Based on the routine from http://jsfiddle.net/MrPolywhirl/NH42z/
125
+
* Rotates the given matrix (array of arrays).
126
+
*
127
+
* Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}.
120
128
*
121
129
* @method
122
-
* @param {array[]} matrix - The array to rotate.
123
-
* @param {number|string} direction - The amount to rotate. Either a number: 90, -90, 270, -270, 180 or a string: 'rotateLeft', 'rotateRight' or 'rotate180'
124
-
* @return {array[]} The rotated array
130
+
* @param {Array<any[]>} matrix - The array to rotate; this matrix _may_ be altered.
131
+
* @param {number|string} direction - The amount to rotate: the roation in degrees (90, -90, 270, -270, 180) or a string command ('rotateLeft', 'rotateRight' or 'rotate180').
132
+
* @return {Array<any[]>} The rotated matrix. The source matrix should be discarded for the returned matrix.
Copy file name to clipboardExpand all lines: src/utils/Utils.js
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -102,25 +102,26 @@ Phaser.Utils = {
102
102
},
103
103
104
104
/**
105
-
* Transposes the elements of the given Array.
105
+
* Transposes the elements of the given matrix (array of arrays).
106
106
*
107
107
* @method Phaser.Utils.transposeArray
108
-
* @param {array[]} array - The array to transpose.
109
-
* @return {array[]} The transposed array.
108
+
* @param {Array<any[]>} array - The matrix to transpose.
109
+
* @return {Array<any[]>} A new transposed matrix
110
110
* @deprecated 2.2.0 - Use Phaser.ArrayUtils.transposeMatrix
111
111
*/
112
112
transposeArray: function(array){
113
113
returnPhaser.ArrayUtils.transposeMatrix(array);
114
114
},
115
115
116
116
/**
117
-
* Rotates the given array.
118
-
* Based on the routine from http://jsfiddle.net/MrPolywhirl/NH42z/
117
+
* Rotates the given matrix (array of arrays).
118
+
*
119
+
* Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}.
119
120
*
120
121
* @method Phaser.Utils.rotateArray
121
-
* @param {array[]} matrix - The array to rotate.
122
-
* @param {number|string} direction - The amount to rotate. Either a number: 90, -90, 270, -270, 180 or a string: 'rotateLeft', 'rotateRight' or 'rotate180'
123
-
* @return {array[]} The rotated array
122
+
* @param {Array<any[]>} matrix - The array to rotate; this matrix _may_ be altered.
123
+
* @param {number|string} direction - The amount to rotate: the roation in degrees (90, -90, 270, -270, 180) or a string command ('rotateLeft', 'rotateRight' or 'rotate180').
124
+
* @return {Array<any[]>} The rotated matrix. The source matrix should be discarded for the returned matrix.
124
125
* @deprecated 2.2.0 - Use Phaser.ArrayUtils.rotateMatrix
0 commit comments