class FlxTypedSpriteGroup<T>
package flixel.group
extends FlxSprite › FlxObject › FlxBasic
import flixel.group.FlxSpriteGroup
extended by FlxTypedSpriteContainer, FlxAnalog, FlxVirtualPad
A FlxSpriteGroup
that only allows specific members to be a specific type of FlxSprite
.
To use any kind of FlxSprite
use FlxSpriteGroup
, which is an alias for
FlxTypedSpriteGroup<FlxSprite>
.
Constructor
Variables
directAlpha:Bool = false
Whether to attempt to preserve the ratio of alpha values of group members, or set them directly through
the alpha property. Defaults to false
(preservation).
4.5.0
.read onlylength: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!
Methods
add(Sprite:T):T
Adds a new FlxSprite
subclass to the group.
Parameters:
Sprite | The sprite or sprite group you want to add to the group. |
---|
Returns:
The same object that was passed in.
inlineclear():Void
Remove all instances of FlxSprite
from the list.
WARNING: does not destroy()
or kill()
any of these objects!
clone():FlxTypedSpriteGroup<T>
Recursive cloning method: it will create a copy of this group which will hold copies of all sprites
Returns:
copy of this sprite group
inlinecountDead():Int
Call this function to find out how many members of the group are dead.
Returns:
The number of FlxSprite
s flagged as dead. Returns -1
if group is empty.
inlinecountLiving():Int
Call this function to find out how many members of the group are not dead.
Returns:
The number of FlxSprite
s flagged as not dead. Returns -1
if group is empty.
destroy():Void
WARNING: A destroyed FlxBasic
can't be used anymore.
It may even cause crashes if it is still part of a group or state.
You may want to use kill()
instead if you want to disable the object temporarily only and revive()
it later.
This function is usually not called manually (Flixel calls it automatically during state switches for all add()
ed objects).
Override this function to null
out variables manually or call destroy()
on class members if necessary.
Don't forget to call super.destroy()
!
findMaxX():Float
Returns the right-most position of the right-most member. If there are no members, x is returned.
5.0.0
.findMaxY():Float
Returns the top-most position of the top-most member. If there are no members, y is returned.
5.0.0
.findMinX():Float
Returns the left-most position of the left-most member. If there are no members, x is returned.
5.0.0
.findMinY():Float
Returns the top-most position of the top-most member. If there are no members, y is returned.
5.0.0
.inlineforEach(Function:T ‑> Void, Recurse:Bool = false):Void
Applies a function to all members.
Parameters:
Function | A function that modifies one element at a time. |
---|---|
Recurse | Whether or not to apply the function to members of subgroups as well. |
inlineforEachAlive(Function:T ‑> Void, Recurse:Bool = false):Void
Applies a function to all alive
members.
Parameters:
Function | A function that modifies one element at a time. |
---|---|
Recurse | Whether or not to apply the function to members of subgroups as well. |
inlineforEachDead(Function:T ‑> Void, Recurse:Bool = false):Void
Applies a function to all dead members.
Parameters:
Function | A function that modifies one element at a time. |
---|---|
Recurse | Whether or not to apply the function to members of subgroups as well. |
inlineforEachExists(Function:T ‑> Void, Recurse:Bool = false):Void
Applies a function to all existing members.
Parameters:
Function | A function that modifies one element at a time. |
---|---|
Recurse | Whether or not to apply the function to members of subgroups as well. |
inlineforEachOfType<K>(ObjectClass:Class<K>, Function:K ‑> Void, Recurse:Bool = false):Void
inlinegetFirstAlive():T
inlinegetFirstAvailable(?ObjectClass:Class<T>, 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.
Parameters:
ObjectClass | An optional parameter that lets you narrow the results to instances of this particular class. |
---|---|
Force | Force the object to be an |
Returns:
A FlxSprite
currently flagged as not existing.
inlinegetFirstDead():T
inlinegetFirstExisting():T
inlinegetFirstNull():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.
inlinegetRandom(StartIndex:Int = 0, Length:Int = 0):T
Returns a member at random from the group.
Parameters:
StartIndex | Optional offset off the front of the array.
Default value is |
---|---|
Length | Optional restriction on the number of values you want to randomly select from. |
Returns:
A FlxSprite
from the members
list.
insert(Position:Int, Sprite:T):T
Inserts a new FlxSprite
subclass to the group at the specified position.
Parameters:
Position | The position that the new sprite or sprite group should be inserted at. |
---|---|
Sprite | The sprite or sprite group you want to insert into the group. |
Returns:
The same object that was passed in.
4.3.0
.isOnScreen(?Camera:FlxCamera):Bool
Check and see if any sprite in this group is currently on screen.
Parameters:
Camera | Specify which game camera you want. If |
---|
Returns:
Whether the object is on screen or not.
inlineiterator(?filter:T ‑> Bool):FlxTypedGroupIterator<T>
Iterate through every member
Returns:
An iterator
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.
loadGraphic(Graphic:FlxGraphicAsset, Animated:Bool = false, Width:Int = 0, Height:Int = 0, Unique:Bool = false, ?Key:String):FlxSprite
This functionality isn't supported in SpriteGroup
Returns:
this sprite group
loadGraphicFromSprite(Sprite:FlxSprite):FlxSprite
This functionality isn't supported in SpriteGroup
Returns:
this sprite group
loadRotatedGraphic(Graphic:FlxGraphicAsset, Rotations:Int = 16, Frame:Int = -1, AntiAliasing:Bool = false, AutoBuffer:Bool = false, ?Key:String):FlxSprite
This functionality isn't supported in SpriteGroup
Returns:
this sprite group
makeGraphic(Width:Int, Height:Int, Color:Int = FlxColor.WHITE, Unique:Bool = false, ?Key:String):FlxSprite
This functionality isn't supported in SpriteGroup
Returns:
this sprite group
multiTransformChildren<V>(FunctionArray:Array<(T, V) ‑> Void>, ValueArray:Array<V>):Void
overlapsPoint(point:FlxPoint, InScreenSpace:Bool = false, ?Camera:FlxCamera):Bool
Checks to see if a point in 2D world space overlaps any FlxSprite
object from this group.
Parameters:
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 |
Returns:
Whether or not the point overlaps this group.
pixelsOverlapPoint(point:FlxPoint, Mask:Int = 0xFF, ?Camera:FlxCamera):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.
Parameters:
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 |
Returns:
Whether or not the point overlaps this object.
inlinerecycle(?ObjectClass:Class<T>, ?ObjectFactory:() ‑> T, 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"
- tries to find the first object with exists == false
- otherwise: adds a new object to the members
array
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!
Parameters:
ObjectClass | The class type you want to recycle (e.g. |
---|---|
ObjectFactory | Optional factory function to create a new object
if there aren't any dead members to recycle.
If |
Force | Force the object to be an |
Revive | Whether recycled members should automatically be revived
(by calling |
Returns:
A reference to the object that was created.
remove(sprite:T, splice:Bool = false):T
Removes the specified sprite from the group.
Parameters:
sprite | The |
---|---|
splice | Whether the object should be cut from the array entirely or not. |
Returns:
The removed sprite.
inlinereplace(oldObject:T, newObject:T):T
Replaces an existing FlxSprite
with a new one.
Parameters:
oldObject | The sprite you want to replace. |
---|---|
newObject | The new object you want to use instead. |
Returns:
The new sprite.
replaceColor(Color:Int, NewColor:Int, FetchPositions:Bool = false):Array<FlxPoint>
Replaces all pixels with specified Color
with NewColor
pixels.
WARNING: very expensive (especially on big graphics) as it iterates over every single pixel.
Parameters:
Color | Color to replace |
---|---|
NewColor | New color |
FetchPositions | Whether we need to store positions of pixels which colors were replaced. |
Returns:
Array
with replaced pixels positions
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.
Parameters:
X | The new x position |
---|---|
Y | The new y position |
inlinesort(Function:(Int, T, T) ‑> Int, Order:Int = FlxSort.ASCENDING):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
group.sort(FlxSort.byY, FlxSort.ASCENDING)
at the bottom of your FlxState#update()
override.
Parameters:
Function | The sorting function to use - you can use one of the premade ones in
|
---|---|
Order | A constant that defines the sort order.
Possible values are |
inlinestamp(Brush:FlxSprite, X:Int = 0, Y:Int = 0):Void
This functionality isn't supported in SpriteGroup
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.
Parameters:
Function | Function to transform the sprites. Example:
|
---|---|
Value | Value which will passed to lambda function. |