class flixel.group.FlxTypedGroup<T> extends FlxBasic

Available on all platforms

This is an organizational class that can update and render a bunch of FlxBasics. * NOTE: Although FlxGroup extends FlxBasic, it will not automatically * add itself to the global collisions quad tree, it will only add its members.

Instance Fields

var length:Int

The number of entries in the members array. For performance and safety you should check this * variable instead of members.length unless you really know what you're doing!

var maxSize:Int

The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.

var members:Array<T>

Array of all the members in this group.

function new(?MaxSize:Int = 0):Void

MaxSize

Maximum amount of members allowed

function add(Object:T):T

Adds a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) to the group. * FlxGroup will try to replace a null member of the array first. * Failing that, FlxGroup will add it to the end of the member array, * assuming there is room for it, and doubling the size of the array if necessary. * WARNING: If the group has a maxSize that has already been met, * the object will NOT be added to the group! * *

Object

The object you want to add to the group. *

returns

The same FlxBasic object that was passed in.

function callAll(FunctionName:String, ?Args:Array<Dynamic> = null, ?Recurse:Bool = true):Void

Go through and call the specified function on all members of the group, recursively by default. * *

FunctionName

The string representation of the function you want to call on each object, for example "kill()" or "init()". *

Args

An array of arguments to call the function with *

Recurse

Default value is true, meaning if callAll() encounters a member that is a group, it will call callAll() on that group rather than calling the group's function.

function clear():Void

Remove all instances of FlxBasic subclass (FlxSprite, FlxBlock, etc) from the list. * WARNING: does not destroy() or kill() any of these objects!

function countDead():Int

Call this function to find out how many members of the group are dead. * *

returns

The number of FlxBasics flagged as dead. Returns -1 if group is empty.

function countLiving():Int

Call this function to find out how many members of the group are not dead. * *

returns

The number of FlxBasics flagged as not dead. Returns -1 if group is empty.

function destroy():Void

WARNING: This will remove this group entirely. Use kill() if you want to disable it * temporarily only and be able to revive() it later. * Override this function to handle any deleting or "shutdown" type operations you might need, * such as removing traditional Flash children like Sprite objects.

function draw():Void

Automatically goes through and calls render on everything you added.

function forEach(Function:T ->Void):Void

Applies a function to all members * *

Function

A function that modifies one element at a time

function forEachAlive(Function:T ->Void):Void

Applies a function to all alive members * *

Function

A function that modifies one element at a time

function forEachDead(Function:T ->Void):Void

Applies a function to all dead members * *

Function

A function that modifies one element at a time

function forEachExists(Function:T ->Void):Void

Applies a function to all existing members * *

Function

A function that modifies one element at a time

function forEachOfType<K>(ObjectClass:Class<K>, Function:K ->Void):Void

Applies a function to all members of type Class * *

ObjectClass

A class that objects will be checked against before Function is applied, ex: FlxSprite *

Function

A function that modifies one element at a time

function getFirstAlive():T

Call this function to retrieve the first object with dead == false in the group. * This is handy for checking if everything's wiped out, or choosing a squad leader, etc. * *

returns

A FlxBasic currently flagged as not dead.

function getFirstAvailable(?ObjectClass:Class<T> = null, ?Force:Bool = false):T

Call this function to retrieve the first object with exists == false in the group. * This is handy for recycling in general, e.g. respawning enemies. * *

ObjectClass

An optional parameter that lets you narrow the results to instances of this particular class. *

Force

Force the object to be an ObjectClass and not a super class of ObjectClass. *

returns

A FlxBasic currently flagged as not existing.

function getFirstDead():T

Call this function to retrieve the first object with dead == true in the group. * This is handy for checking if everything's wiped out, or choosing a squad leader, etc. * *

returns

A FlxBasic currently flagged as dead.

function getFirstExisting():T

Call this function to retrieve the first object with exists == true in the group. * This is handy for checking if everything's wiped out, or choosing a squad leader, etc. * *

returns

A FlxBasic currently flagged as existing.

function getFirstNull():Int

Call this function to retrieve the first index set to 'null'. * Returns -1 if no index stores a null object. * *

returns

An Int indicating the first null slot in the group.

function getRandom(?StartIndex:Int = 0, ?Length:Int = 0):T

Returns a member at random from the group. * *

StartIndex

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

Length

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

returns

A FlxBasic from the members list.

function iterator(?filter:T ->Bool = null):FlxTypedGroupIterator<T>

Iterate through every member * *

returns

An iterator

function kill():Void

Calls kill on the group's members and then on the group itself. * You can revive this group later via revive() after this.

function recycle(?ObjectClass:Class<T> = null, ?ContructorArgs:Array<Dynamic> = null, ?Force:Bool = false, ?Revive:Bool = true):T

Recycling is designed to help you reuse game objects without always re-allocating or "newing" them. * It behaves differently depending on whether maxSize equals 0 or is bigger than 0. * * maxSize == 0 / "rotating-recycling" (used by FlxEmitter): * - at capacity: returns the next object in line, no matter its properties like alive, exists etc. * - otherwise: returns a new object. * * maxSize > 0 / "grow-style-recycling" * - at capacity: tries to find the first object with exists == false, or if none found: * - otherwise: adds a new object to the members array, doubling its size if necessary * * WARNING: If this function needs to create a new object, and no object class was provided, * it will return null instead of a valid object! * *

ObjectClass

The class type you want to recycle (e.g. FlxSprite, EvilRobot, etc). Do NOT "new" the class in the parameter! *

ContructorArgs

An array of arguments passed into a newly object if there aren't any dead members to recycle. *

Force

Force the object to be an ObjectClass and not a super class of ObjectClass. *

Revive

Whether recycled members should automatically be revived (by calling revive() on them) *

returns

A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).

function remove(Object:T, ?Splice:Bool = false):T

Removes an object from the group. * *

Object

The FlxBasic you want to remove. *

Splice

Whether the object should be cut from the array entirely or not. *

returns

The removed object.

function replace(OldObject:T, NewObject:T):T

Replaces an existing FlxBasic with a new one. * Does not do anything and returns null if the old object is not part of the group. * *

OldObject

The object you want to replace. *

NewObject

The new object you want to use instead. *

returns

The new object.

function setAll(VariableName:String, Value:Dynamic, ?Recurse:Bool = true):Void

Go through and set the specified variable to the specified value on all members of the group. * *

VariableName

The string representation of the variable name you want to modify, for example "visible" or "scrollFactor". *

Value

The value you want to assign to that variable. *

Recurse

Default value is true, meaning if setAll() encounters a member that is a group, it will call setAll() on that group rather than modifying its variable.

function sort(Function:Int ->T ->T ->Int, ?Order:Int = -1):Void

Call this function to sort the group according to a particular value and order. For example, to sort game objects for Zelda-style * overlaps you might call myGroup.sort(FlxSort.byY, FlxSort.ASCENDING) at the bottom of your FlxState.update() override. * *

Function

The sorting function to use - you can use one of the premade ones in FlxSort or write your own using FlxSort.byValues() as a backend *

Order

A FlxGroup constant that defines the sort order. Possible values are FlxSort.ASCENDING (default) and FlxSort.DESCENDING.

function update():Void

Automatically goes through and calls update on everything you added.