FlxTypedEmitter is a lightweight particle emitter. It can be used for one-time explosions or for continuous fx like rain and fire. FlxEmitter is not optimized or anything; all it does is launch FlxParticle objects out at set intervals by setting their positions and velocities accordingly. It is easy to use and relatively efficient, relying on FlxGroup's RECYCLE POWERS.

Constructor

@:value({ Size : 0, Y : 0, X : 0 })new(X:Float = 0, Y:Float = 0, Size:Int = 0)

Creates a new FlxTypedEmitter object at a specific position. Does NOT automatically generate or attach particles!

Parameters:

X

The X position of the emitter.

Y

The Y position of the emitter.

Size

Optional, specifies a maximum capacity for this emitter.

Variables

@:value(new FlxPointRangeBounds(0, 0))read onlyacceleration:FlxPointRangeBounds = new FlxPointRangeBounds(0, 0)

Sets the acceleration range of particles launched from this emitter. Set acceleration y-values to give particles gravity.

@:value(NONE)allowCollisions:FlxDirectionFlags = NONE

Sets the allowCollisions value for particles launched from this emitter. Set to NONE by default. Don't forget to call FlxG.collide() in your update loop!

@:value(new FlxRangeBounds<Float>(1))read onlyalpha:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(1)

Sets alpha range of particles launched from this emitter.

@:value(new FlxRangeBounds<Float>(0))read onlyangle:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0)

The angle range of particles launched from this emitter. angle.end is ignored unless ignoreAngularVelocity is set to true.

@:value(new FlxRangeBounds<Float>(0, 0))read onlyangularAcceleration:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0, 0)

Set the angular acceleration range of particles launched from this emitter.

@:value(new FlxRangeBounds<Float>(0, 0))read onlyangularDrag:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0, 0)

Set the angular drag range of particles launched from this emitter.

@:value(new FlxRangeBounds<Float>(0, 0))read onlyangularVelocity:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0, 0)

The angular velocity range of particles launched from this emitter.

@:value(false)autoUpdateHitbox:Bool = false

Sets the autoUpdateHitbox flag for particles launched from this emitter. If true, the particles' hitbox will be updated to match scale.

blend:BlendMode

Sets particle's blend mode. null by default. Warning: Expensive on Flash.

@:value(new FlxRangeBounds(FlxColor.WHITE, FlxColor.WHITE))read onlycolor:FlxRangeBounds<FlxColor> = new FlxRangeBounds(FlxColor.WHITE, FlxColor.WHITE)

Sets color range of particles launched from this emitter.

@:value(new FlxPointRangeBounds(0, 0))read onlydrag:FlxPointRangeBounds = new FlxPointRangeBounds(0, 0)

Sets X and Y drag component of particles launched from this emitter.

@:value(new FlxRangeBounds<Float>(0))read onlyelasticity:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0)

Sets the elasticity, or bounce, range of particles launched from this emitter.

@:value(false)emitting:Bool = false

Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this.

@:value(0.1)frequency:Float = 0.1

How often a particle is emitted (if emitter is started with Explode == false).

@:value(0)height:Float = 0

The height of this emitter. Particles can be randomly generated from anywhere within this box.

@:value(false)ignoreAngularVelocity:Bool = false

Set this if you want to specify the beginning and ending value of angle, instead of using angularVelocity (or angularAcceleration).

@:value(false)immovable:Bool = false

Sets the immovable flag for particles launched from this emitter.

@:value(false)keepScaleRatio:Bool = false

Keep the scale ratio of the particle. Uses the x values of scale.

@:value(new FlxBounds<Float>(-180, 180))read onlylaunchAngle:FlxBounds<Float> = new FlxBounds<Float>(-180, 180)

The angle range at which particles will be launched from this emitter. Ignored unless launchMode is set to FlxEmitterMode.CIRCLE.

@:value(FlxEmitterMode.CIRCLE)launchMode:FlxEmitterMode = FlxEmitterMode.CIRCLE

How particles should be launched. If CIRCLE, particles will use launchAngle and speed. Otherwise, particles will just use velocity.x and velocity.y.

@:value(new FlxBounds<Float>(3))read onlylifespan:FlxBounds<Float> = new FlxBounds<Float>(3)

The life, or duration, range of particles launched from this emitter.

@:value(cast FlxParticle)particleClass:Class<T> = cast FlxParticle

Set your own particle class type here. The custom class must extend FlxParticle. Default is FlxParticle.

@:value(new FlxPointRangeBounds(1, 1))read onlyscale:FlxPointRangeBounds = new FlxPointRangeBounds(1, 1)

Sets scale range of particles launched from this emitter.

solid:Bool

Shorthand for toggling allowCollisions between ANY (if true) and NONE (if false). Don't forget to call FlxG.collide() in your update loop!

@:value(new FlxRangeBounds<Float>(0, 100))read onlyspeed:FlxRangeBounds<Float> = new FlxRangeBounds<Float>(0, 100)

Set the speed range of particles launched from this emitter. Only used with FlxEmitterMode.CIRCLE.

@:value(new FlxPointRangeBounds(-100, -100, 100, 100))read onlyvelocity:FlxPointRangeBounds = new FlxPointRangeBounds(-100, -100, 100, 100)

Sets the velocity range of particles launched from this emitter. Only used with FlxEmitterMode.SQUARE.

@:value(0)width:Float = 0

The width of this emitter. Particles can be randomly generated from anywhere within this box.

@:value(0)x:Float = 0

The x position of this emitter.

@:value(0)y:Float = 0

The y position of this emitter.

Methods

destroy():Void

Clean up memory.

emitParticle():T

This function can be used both internally and externally to emit the next particle.

focusOn(Object:FlxObject):Void

Change the emitter's midpoint to match the midpoint of a FlxObject.

Parameters:

Object

The FlxObject that you want to sync up with.

kill():Void

Call this function to turn off all the particles and the emitter.

@:value({ AutoBuffer : false, Multiple : false, bakedRotationAngles : 16, Quantity : 50 })loadParticles(Graphics:FlxGraphicAsset, Quantity:Int = 50, bakedRotationAngles:Int = 16, Multiple:Bool = false, AutoBuffer:Bool = false):FlxTypedEmitter<T>

This function generates a new array of particle sprites to attach to the emitter.

Parameters:

Graphics

If you opted to not pre-configure an array of FlxParticle objects, you can simply pass in a particle image or sprite sheet.

Quantity

The number of particles to generate when using the "create from image" option.

BakedRotations

How many frames of baked rotation to use (boosts performance). Set to zero to not use baked rotations.

Multiple

Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!).

AutoBuffer

Whether to automatically increase the image size to accommodate rotated corners. Default is false. Will create frames that are 150% larger on each axis than the original frame or graphic.

Returns:

This FlxEmitter instance (nice for chaining stuff together).

@:value({ Quantity : 50, Color : FlxColor.WHITE, Height : 2, Width : 2 })makeParticles(Width:Int = 2, Height:Int = 2, Color:FlxColor = FlxColor.WHITE, Quantity:Int = 50):FlxTypedEmitter<T>

Similar to FlxSprite#makeGraphic(), this function allows you to quickly make single-color particles.

Parameters:

Width

The width of the generated particles. Default is 2 pixels.

Height

The height of the generated particles. Default is 2 pixels.

Color

The color of the generated particles. Default is white.

Quantity

How many particles to generate. Default is 50.

Returns:

This FlxEmitter instance (nice for chaining stuff together).

@:value({ Y : 0, X : 0 })inlinesetPosition(X:Float = 0, Y:Float = 0):Void

Helper function to set the coordinates of this object.

inlinesetSize(Width:Float, Height:Float):Void

@:value({ Quantity : 0, Frequency : 0.1, Explode : true })start(Explode:Bool = true, Frequency:Float = 0.1, Quantity:Int = 0):FlxTypedEmitter<T>

Call this function to start emitting particles.

Parameters:

Explode

Whether the particles should all burst out at once.

Frequency

Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds.

Quantity

How many particles to launch. 0 = "all of the particles".

Returns:

This FlxEmitter instance (nice for chaining stuff together).

update(elapsed:Float):Void

Called automatically by the game loop, decides when to launch particles and when to "die".

Inherited Variables

Defined by FlxTypedGroup

@:value(0)read onlylength:Int = 0

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!

maxSize:Int

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

read onlymemberAdded:FlxTypedSignal<T ‑> Void>

A FlxSignal that dispatches when a child is added to this group.

Available since

4.4.0

.

read onlymemberRemoved:FlxTypedSignal<T ‑> Void>

A FlxSignal that dispatches when a child is removed from this group.

Available since

4.4.0

.

read onlymembers:Array<T>

Array of all the members in this group.

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxTypedGroup

add(basic: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. WARNING: If the group has a maxSize that has already been met, the object will NOT be added to the group!

Parameters:

basic

The FlxBasic you want to add to the group.

Returns:

The same FlxBasic object that was passed in.

any(func:T ‑> Bool):Bool

Tests whether any member satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

clear():Void

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

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.

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.

draw():Void

Automatically goes through and calls render on everything you added.

every(func:T ‑> Bool):Bool

Tests whether every member satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

@:value({ recurse : false })forEach(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachAlive(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all alive members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachDead(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all dead members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachExists(func:T ‑> Void, recurse:Bool = false):Void

Applies a function to all existing members.

Parameters:

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

@:value({ recurse : false })forEachOfType<K>(objectClass:Class<K>, func:K ‑> Void, recurse:Bool = false):Void

Applies a function to all members of type Class<K>.

Parameters:

objectClass

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

func

A function that modifies one element at a time.

recurse

Whether or not to apply the function to members of subgroups as well.

getFirst(func:T ‑> Bool):Null<T>

Searches for, and returns the first member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

getFirstAlive():Null<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.

@:value({ force : false })getFirstAvailable(?objectClass:Class<T>, force:Bool = false):Null<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 ObjectClass and not a super class of ObjectClass.

Returns:

A FlxBasic currently flagged as not existing.

getFirstDead():Null<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.

getFirstExisting():Null<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.

getFirstIndex(func:T ‑> Bool):Int

Searches for, and returns the index of the first member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

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.

getLast(func:T ‑> Bool):Null<T>

Searches for, and returns the last member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

getLastIndex(func:T ‑> Bool):Int

Searches for, and returns the index of the last member that satisfies the function.

Parameters:

func

The function that tests the members

Available since

5.4.0

.

@:value({ length : 0, startIndex : 0 })getRandom(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 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.

insert(position:Int, object:T):T

Inserts a new FlxBasic subclass (FlxBasic, FlxSprite, Enemy, etc) into the group at the specified position. FlxGroup will try to replace a null member at the specified position of the array first. Failing that, FlxGroup will insert it at the position of the member array. WARNING: If the group has a maxSize that has already been met, the object will NOT be inserted to the group!

Parameters:

position

The position in the group where you want to insert the object.

object

The object you want to insert into the group.

Returns:

The same FlxBasic object that was passed in.

inlineiterator(?filter:T ‑> Bool):FlxTypedGroupIterator<T>

Iterates through every member.

inlinekeyValueIterator():ArrayKeyValueIterator<T>

Iterates through every member and index.

killMembers():Void

Calls kill() on the group's unkilled members. Revive them via reviveMembers().

Available since

5.4.0

.

@:value({ revive : true, force : false })recycle(?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. FlxSprite, EvilRobot, etc).

objectFactory

Optional factory function to create a new object if there aren't any dead members to recycle. If null, Type.createInstance() is used, which requires the class to have no constructor parameters.

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.

@:value({ splice : false })remove(basic:T, splice:Bool = false):T

Removes an object from the group.

Parameters:

basic

The FlxBasic you want to remove.

splice

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

Returns:

The removed object.

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.

Parameters:

oldObject

The object you want to replace.

newObject

The new object you want to use instead.

Returns:

The new object.

revive():Void

Calls reviveMembers() and then revives the group itself.

reviveMembers():Void

Calls revive() on the group's killed members and then on the group itself.

Available since

5.4.0

.

@:value({ order : FlxSort.ASCENDING })inlinesort(func:(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:

func

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 constant that defines the sort order. Possible values are FlxSort.ASCENDING (default) and FlxSort.DESCENDING.

Defined by FlxBasic

getCameras():Array<FlxCamera>

The cameras that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's cameras are used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then the default draw cameras are returned.

Available since

5.7.0

.