class flixel.group.FlxTypedSpriteGroup<T> extends FlxSprite

Available on all platforms

FlxSpriteGroup is a special FlxGroup that can be treated like * a single sprite even if it's made up of several member sprites.

Instance Fields

var group:FlxTypedGroup<T>

The actual group which holds all sprites

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>

The link to a group's members array

function new(?X:Float = 0, ?Y:Float = 0, ?MaxSize:Int = 0):Void

X

The initial X position of the group *

Y

The initial Y position of the group *

MaxSize

Maximum amount of members allowed

function add(Sprite:T):T

Adds a new FlxSprite subclass to the group. * *

Object

The sprite or sprite group you want to add to the group. *

returns

The same 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. * Currently only works on functions that have no required parameters. * *

FunctionName

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

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 FlxSprite from the list. * WARNING: does not destroy() or kill() any of these objects!

function clone(?NewSprite:FlxSprite = null):FlxTypedSpriteGroup<T>

Recursive cloning method: it will create copy of this group which will hold copies of all sprites * *

NewSprite

optional sprite group to copy to *

returns

copy of this sprite group

function countDead():Int

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

returns

The number of FlxSprites 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 FlxSprites flagged as not dead. Returns -1 if group is empty.

function destroy():Void

WARNING: This will remove this object entirely. Use kill() if you want to disable it temporarily only and reset() it later to revive it. * Override this function to null out variables manually or call destroy() on class members if necessary. Don't forget to call super.destroy()!

function draw():Void

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 FlxSprite 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 FlxSprite 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 FlxSprite 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 FlxSprite 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 FlxSprite from the members list.

function isOnScreen(?Camera:FlxCamera = null):Bool

Check and see if any sprite in this group is currently on screen. * *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether the object is on screen or not.

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 loadGraphic(Graphic:Dynamic, ?Animated:Bool = false, ?Width:Int = 0, ?Height:Int = 0, ?Unique:Bool = false, ?Key:String = null):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function loadGraphicFromSprite(Sprite:FlxSprite):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function loadGraphicFromTexture(Data:Dynamic, ?Unique:Bool = false, ?FrameName:String = null):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function loadRotatedGraphic(Graphic:Dynamic, ?Rotations:Int = 16, ?Frame:Int = -1, ?AntiAliasing:Bool = false, ?AutoBuffer:Bool = false, ?Key:String = null):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function loadRotatedGraphicFromTexture(Data:Dynamic, Image:String, ?Rotations:Int = 16, ?AntiAliasing:Bool = false, ?AutoBuffer:Bool = false):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function makeGraphic(Width:Int, Height:Int, ?Color:Int = -1, ?Unique:Bool = false, ?Key:String = null):FlxSprite

This functionality isn't supported in SpriteGroup *

returns

this sprite group

function multiTransformChildren<V>(FunctionArray:Array<T ->V ->Void>, ValueArray:Array<V>):Void

Handy function that allows you to quickly transform multiple properties of sprites in this group at a time. * *

FunctionArray

Array of functions to transform sprites in this group. *

ValueArray

Array of values which will be passed to lambda functions

function multiTransformChildren_Float(FunctionArray:Array<T ->Float ->Void>, ValueArray:Array<Float>):Void

function overlapsPoint(point:FlxPoint, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):Bool

Checks to see if a point in 2D world space overlaps any FlxSprite object from this group. * *

Point

The point in world space you want to check. *

InScreenSpace

Whether to take scroll factors into account when checking for overlap. *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether or not the point overlaps this group.

function pixelsOverlapPoint(point:FlxPoint, ?Mask:Int = 255, ?Camera:FlxCamera = null):Bool

Checks to see if a point in 2D world space overlaps any of FlxSprite object's current displayed pixels. * This check is ALWAYS made in screen space, and always takes scroll factors into account. * *

Point

The point in world space you want to check. *

Mask

Used in the pixel hit test to determine what counts as solid. *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

returns

Whether or not the point overlaps this object.

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

Recycling is designed to help you reuse game objects without always re-allocating or "newing" them. * *

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

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 specified sprite from the group. * *

Object

The FlxSprite 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 FlxSprite with a new one. * *

OldObject

The object you want to replace. *

NewObject

The new object you want to use instead. *

returns

The new object.

function replaceColor(Color:Int, NewColor:Int, ?FetchPositions:Bool = false):Array<FlxPoint>

Replaces all pixels with specified Color with NewColor pixels. This operation is applied to every nested sprite from this group * *

Color

Color to replace *

NewColor

New color *

FetchPositions

Whether we need to store positions of pixels which colors were replaced *

returns

Array replaced pixels positions

function reset(X:Float, Y:Float):Void

Helper function for the sort process. * *

Obj1

The first object being sorted. *

Obj2

The second object being sorted. *

returns

An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).

function revive():Void

Revives the group.

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 setPosition(?X:Float = 0, ?Y:Float = 0):Void

Helper function to set the coordinates of this object. * Handy since it only requires one line of code. * *

X

The new x position *

Y

The new y position

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 stamp(Brush:FlxSprite, ?X:Int = 0, ?Y:Int = 0):Void

This functionality isn't supported in SpriteGroup

function transformChildren<V>(Function:T ->V ->Void, Value:V):Void

Handy function that allows you to quickly transform one property of sprites in this group at a time. * *

Function

Function to transform the sprites. Example: function(s:FlxSprite, v:Dynamic) { s.acceleration.x = v; s.makeGraphic(10,10,0xFF000000); } *

Value

Value which will passed to lambda function

function transformChildren_Bool(Function:T ->Bool ->Void, Value:Bool):Void

function transformChildren_Float(Function:T ->Float ->Void, Value:Float):Void

function transformChildren_Int(Function:T ->Int ->Void, Value:Int):Void

function update():Void

function updateFrameData():Void

This functionality isn't supported in SpriteGroup