class FlxArrayUtil
package flixel.util
A set of functions for array manipulation.
Static methods
staticclearArray<T>(array:Array<T>, recursive:Bool = false):Array<T>
Clears an array structure, but leaves the object data untouched Useful for cleaning up temporary references to data you want to preserve. WARNING: Can lead to memory leaks.
Parameters:
array | The array to clear out |
---|---|
Recursive | Whether to search for arrays inside of arr and clear them out, too |
staticequals<T>(array1:Array<T>, array2:Array<T>):Bool
Compares the contents with ==
to see if the two arrays are the same.
Also takes null arrays and the length of the arrays into account.
staticinlinefastSplice<T>(array:Array<T>, element:T):Array<T>
Safely removes an element from an array by swapping it with the last element and calling pop()
(won't do anything if the element is not in the array). This is a lot faster than regular splice()
,
but it can only be used on arrays where order doesn't matter.
Parameters:
array | The array to remove the element from |
---|---|
element | The element to remove from the array |
Returns:
The array
staticflatten2DArray<T>(array:Array<Array<T>>):Array<T>
Flattens 2D arrays into 1D arrays.
Example: [[1, 2], [3, 2], [1, 1]]
-> [1, 2, 3, 2, 1, 1]
staticlast<T>(array:Array<T>):Null<T>
Returns the last element of an array or null
if the array is null
/ empty.
staticsafePush<T>(array:Array<T>, element:T):Array<T>
Pushes the element into the array (and if the array is null, creates it first) and returns the array.
4.6.0
.staticsetLength<T>(array:Array<T>, newLength:Int):Array<T>
Sets the length of an array.
Parameters:
array | The array. |
---|---|
newLength | The length you want the array to have. |
staticinlineswapAndPop<T>(array:Array<T>, index:Int):Array<T>
Removes an element from an array by swapping it with the last element and calling pop()
.
This is a lot faster than regular splice()
, but it can only be used on arrays where order doesn't matter.
IMPORTANT: always count down from length to zero if removing elements from within a loop
using flixel.util.FlxArrayUtil;
var i = array.length;
while (i-- > 0)
{
if (array[i].shouldRemove)
{
array.swapAndPop(i);
}
}
Parameters:
array | The array to remove the element from |
---|---|
index | The index of the element to be removed from the array |
Returns:
The array