ParticleEmitter
A powerful and flexible particle emitter system for creating visual effects.
ParticleEmitter manages the creation, animation, and recycling of particles to create effects like fire, smoke, explosions, rain, snow, and more. The emitter can be attached as a component to any Visual entity.
Features:
- Continuous or burst emission modes
- Full control over particle properties and their evolution over time
- Efficient particle pooling and recycling
- Support for custom particle visuals
- Deterministic random generation with seeding
- Launch modes: circular (angle-based) or square (velocity-based)
Particle properties that can be animated over lifetime:
- Position, velocity, acceleration, and drag
- Scale, rotation, and angular velocity
- Color and alpha transparency
- Custom ranges for randomization
// Create a fire effect
var fire = new ParticleEmitter();
fire.launchMode = CIRCLE;
fire.launchAngle(-90, -90);
fire.speedStart(100, 150);
fire.lifespan(0.5, 1.0);
fire.scaleStart(0.5, 1.0);
fire.scaleEnd(0.1, 0.2);
fire.colorStart(Color.YELLOW, Color.ORANGE);
fire.colorEnd(Color.RED);
fire.alphaEnd(0);
fire.emitContinuously(0.05);
myVisual.component('particles', fire);
// Create an explosion
var explosion = new ParticleEmitter();
explosion.speedStart(200, 400);
explosion.lifespan(0.3, 0.6);
explosion.scaleEnd(2.0);
explosion.alphaEnd(0);
explosion.explode(50); // Emit 50 particles at once
Instance Members
observedDirty: BoolDefault is false, automatically set to true when any of this instance's observable variables has changed.
entity: VisualThe visual entity this emitter is attached to when used as a component. Particles will be added as children of this visual.
visual: VisualThe visual that particles are added to as children. Can be set directly or automatically assigned when used as a component. If null, particles won't be displayed.
Determines whether the emitter is currently emitting particles or not
paused: BoolDetermines whether the emitter is currently paused. It is totally safe to directly toggle this.
interval: FloatHow often a particle is emitted, if currently emitting. Can be modified at the middle of an emission safely;
How particles should be launched. If CIRCLE (default), particles will use launchAngle and speed.
Otherwise, particles will just use velocityX and velocityY.
keepScaleRatio: BoolKeep the scale ratio of the particle. Uses the scaleX value for reference.
visualScaleActive: BoolApply particle scale to underlying visual or not.
visualColorActive: BoolApply particle color to underlying visual or not.
visualPositionActive: BoolApply particle position (x & y) to underlying visual or not.
visualRotationActive: BoolApply particle angle to underlying visual rotation or not.
visualAlphaActive: BoolApply particle alpha to underlying visual or not.
width: FloatThe width of the emission area.
If not defined (-1), will use visual's width bound to this ParticleEmitter object, if any
height: FloatThe height of the emission area.
If not defined (-1), will use visual's height bound to this ParticleEmitter object, if any
x: FloatThe x position of the emission, relative to particles parent (if any)
y: FloatThe y position of the emission, relative to particles parent (if any)
maxVelocityX: FloatIf you are using acceleration, you can use maxVelocity with it
to cap the speed automatically (very useful!).
maxVelocityY: FloatIf you are using acceleration, you can use maxVelocity with it
to cap the speed automatically (very useful!).
velocityActive: BoolEnable or disable the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityStartMinX: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityStartMinY: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityStartMaxX: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityStartMaxY: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityEndMinX: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityEndMinY: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityEndMaxX: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
velocityEndMaxY: FloatSets the velocity range of particles launched from this emitter. Only used with SQUARE.
speedStartMin: FloatSet the speed range of particles launched from this emitter. Only used with CIRCLE.
speedStartMax: FloatSet the speed range of particles launched from this emitter. Only used with CIRCLE.
speedEndMin: FloatSet the speed range of particles launched from this emitter. Only used with CIRCLE.
speedEndMax: FloatSet the speed range of particles launched from this emitter. Only used with CIRCLE.
maxAngularVelocity: FloatUse in conjunction with angularAcceleration for fluid spin speed control.
angularAccelerationActive: BoolEnable or disable the angular acceleration range of particles launched from this emitter.
angularAccelerationStartMin: FloatSet the angular acceleration range of particles launched from this emitter.
angularAccelerationStartMax: FloatSet the angular acceleration range of particles launched from this emitter.
angularDragActive: BoolEnable or disable the angular drag range of particles launched from this emitter.
angularDragStartMin: FloatSet the angular drag range of particles launched from this emitter.
angularDragStartMax: FloatSet the angular drag range of particles launched from this emitter.
angularVelocityActive: BoolEnable or disable the angular velocity range of particles launched from this emitter.
angularVelocityStartMin: FloatThe angular velocity range of particles launched from this emitter.
angularVelocityStartMax: FloatThe angular velocity range of particles launched from this emitter.
angularVelocityEndMin: FloatThe angular velocity range of particles launched from this emitter.
angularVelocityEndMax: FloatThe angular velocity range of particles launched from this emitter.
angleActive: BoolEnable or disable the angle range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
angleStartMin: FloatThe angle range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
angleStartMax: FloatThe angle range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
angleEndMin: FloatThe angle range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
angleEndMax: FloatThe angle range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
ignoreAngularVelocity: BoolSet this if you want to specify the beginning and ending value of angle,
instead of using angularVelocity (or angularAcceleration).
launchAngleActive: BoolEnable or disable the angle range at which particles will be launched from this emitter.
Ignored unless launchMode is set to CIRCLE.
launchAngleMin: FloatThe angle range at which particles will be launched from this emitter.
Ignored unless launchMode is set to CIRCLE.
launchAngleMax: FloatThe angle range at which particles will be launched from this emitter.
Ignored unless launchMode is set to CIRCLE.
lifespanActive: BoolEnable or disable the life, or duration, range of particles launched from this emitter.
lifespanMin: FloatThe life, or duration, range of particles launched from this emitter.
lifespanMax: FloatThe life, or duration, range of particles launched from this emitter.
scaleActive: BoolEnable or disable scale range of particles launched from this emitter.
scaleStartMinX: FloatSets scale range of particles launched from this emitter.
scaleStartMinY: FloatSets scale range of particles launched from this emitter.
scaleStartMaxX: FloatSets scale range of particles launched from this emitter.
scaleStartMaxY: FloatSets scale range of particles launched from this emitter.
scaleEndMinX: FloatSets scale range of particles launched from this emitter.
scaleEndMinY: FloatSets scale range of particles launched from this emitter.
scaleEndMaxX: FloatSets scale range of particles launched from this emitter.
scaleEndMaxY: FloatSets scale range of particles launched from this emitter.
alphaActive: BoolEnable or disable alpha range of particles launched from this emitter.
alphaStartMin: FloatSets alpha range of particles launched from this emitter.
alphaStartMax: FloatSets alpha range of particles launched from this emitter.
alphaEndMin: FloatSets alpha range of particles launched from this emitter.
alphaEndMax: FloatSets alpha range of particles launched from this emitter.
colorActive: BoolEnable or disable color range of particles launched from this emitter.
colorStartMin: ColorSets color range of particles launched from this emitter.
colorStartMax: ColorSets color range of particles launched from this emitter.
colorEndMin: ColorSets color range of particles launched from this emitter.
colorEndMax: ColorSets color range of particles launched from this emitter.
dragActive: BoolEnable or disable X and Y drag component of particles launched from this emitter.
dragStartMinX: FloatSets X and Y drag component of particles launched from this emitter.
dragStartMinY: FloatSets X and Y drag component of particles launched from this emitter.
dragStartMaxX: FloatSets X and Y drag component of particles launched from this emitter.
dragStartMaxY: FloatSets X and Y drag component of particles launched from this emitter.
dragEndMinX: FloatSets X and Y drag component of particles launched from this emitter.
dragEndMinY: FloatSets X and Y drag component of particles launched from this emitter.
dragEndMaxX: FloatSets X and Y drag component of particles launched from this emitter.
dragEndMaxY: FloatSets X and Y drag component of particles launched from this emitter.
accelerationActive: BoolEnable or disable the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationStartMinX: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationStartMinY: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationStartMaxX: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationStartMaxY: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationEndMinX: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationEndMinY: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationEndMaxX: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
accelerationEndMaxY: FloatSets the acceleration range of particles launched from this emitter.
Set acceleration y-values to give particles gravity.
seed: FloatA random seed used to generated particles. Provide a custom seed to reproduce same chain of particles.
initializerName: StringThe width and height of the emission area.
If not defined (-1), will use visual's width and height bound to this ParticleEmitter object, if any
| Name | Type |
|---|---|
width |
Float |
height |
Float |
The x and y position of the emission, relative to particles parent (if any)
| Name | Type |
|---|---|
x |
Float |
y |
Float |
If you are using acceleration, you can use maxVelocity with it
to cap the speed automatically (very useful!).
| Name | Type |
|---|---|
maxVelocityX |
Float |
maxVelocityY |
Float |
Sets the velocity starting range of particles launched from this emitter. Only used with SQUARE.
| Name | Type | Default |
|---|---|---|
startMinX |
Float | |
startMinY |
Float | |
startMaxX |
Float | (optional) |
startMaxY |
Float | (optional) |
Sets the velocity ending range of particles launched from this emitter. Only used with SQUARE.
| Name | Type | Default |
|---|---|---|
endMinX |
Float | |
endMinY |
Float | |
endMaxX |
Float | (optional) |
endMaxY |
Float | (optional) |
Set the speed starting range of particles launched from this emitter. Only used with CIRCLE.
| Name | Type | Default |
|---|---|---|
startMin |
Float | |
startMax |
Float | (optional) |
Set the speed ending range of particles launched from this emitter. Only used with CIRCLE.
| Name | Type | Default |
|---|---|---|
endMin |
Float | |
endMax |
Float | (optional) |
Set the angular acceleration range of particles launched from this emitter.
| Name | Type |
|---|---|
startMin |
Float |
startMax |
Float |
Set the angular drag range of particles launched from this emitter.
| Name | Type |
|---|---|
startMin |
Float |
startMax |
Float |
The angular velocity starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMin |
Float | |
startMax |
Float | (optional) |
The angular velocity ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMin |
Float | |
endMax |
Float | (optional) |
The angle starting range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
| Name | Type | Default |
|---|---|---|
startMin |
Float | |
startMax |
Float | (optional) |
The angle ending range of particles launched from this emitter.
angleEndMin and angleEndMax are ignored unless ignoreAngularVelocity is set to true.
| Name | Type | Default |
|---|---|---|
endMin |
Float | |
endMax |
Float | (optional) |
The angle range at which particles will be launched from this emitter.
Ignored unless launchMode is set to CIRCLE.
| Name | Type |
|---|---|
min |
Float |
max |
Float |
The life, or duration, range of particles launched from this emitter.
| Name | Type |
|---|---|
min |
Float |
max |
Float |
Sets scale starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMinX |
Float | |
startMinY |
Float | |
startMaxX |
Float | (optional) |
startMaxY |
Float | (optional) |
Sets scale ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMinX |
Float | |
endMinY |
Float | |
endMaxX |
Float | (optional) |
endMaxY |
Float | (optional) |
Sets acceleration starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMinX |
Float | |
startMinY |
Float | |
startMaxX |
Float | (optional) |
startMaxY |
Float | (optional) |
Sets acceleration ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMinX |
Float | |
endMinY |
Float | |
endMaxX |
Float | (optional) |
endMaxY |
Float | (optional) |
Sets drag starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMinX |
Float | |
startMinY |
Float | |
startMaxX |
Float | (optional) |
startMaxY |
Float | (optional) |
Sets drag ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMinX |
Float | |
endMinY |
Float | |
endMaxX |
Float | (optional) |
endMaxY |
Float | (optional) |
Sets color starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMin |
Color | |
startMax |
Color | (optional) |
Sets color ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMin |
Color | |
endMax |
Color | (optional) |
Sets alpha starting range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
startMin |
Float | |
startMax |
Float | (optional) |
Sets alpha ending range of particles launched from this emitter.
| Name | Type | Default |
|---|---|---|
endMin |
Float | |
endMax |
Float | (optional) |
invalidateStatus(): VoidCustom particle visual creation callback.
Use this to emit custom visuals as particles. The callback receives an existing visual (if being recycled) and should return a visual to use for the particle.
Alternative approach: Create a subclass and override getParticleVisual().
| Name | Type | Description |
|---|---|---|
existingVisual |
Visual | A recycled visual if available, null otherwise |
| Returns | Description |
|---|---|
| Visual | The visual to use for the particle * haxe emitter.getCustomParticleVisual = (existing) -> { if (existing != null) return existing; var sprite = new Quad(); sprite.texture = sparkTexture; sprite.anchor(0.5, 0.5); return sprite; }; |
destroy(): VoidDestroys the emitter and cleans up resources.
If the emitter has no associated visual (not attached as component), all active particle visuals without parents are also destroyed. This prevents memory leaks from orphaned particles.
Starts emitting particles continuously at regular intervals.
Creates a stream of particles over time. Useful for effects like:
- Fire, smoke, steam
- Rain, snow, falling leaves
- Fountains, waterfalls
- Magic sparkles, energy beams
| Name | Type | Default | Description |
|---|---|---|---|
interval |
Float | 0.1 |
Time between particle emissions in seconds. Examples: 0.1 = 10 particles/second, 0.01 = 100 particles/second. Set to 0 or less to stop emission. |
quantity |
Int | -1 |
Total particles to emit before stopping. -1 = infinite (default), 0 = stop immediately, positive = emit that many then stop. * haxe // Continuous smoke emitter.emitContinuously(0.05); // 20 particles per second, forever * // Limited burst emitter.emitContinuously(0.1, 50); // 10/second, stop after 50 |
Emits a burst of particles all at once.
Creates an instant explosion of particles. Useful for effects like:
- Explosions, impacts, hits
- Confetti, fireworks
- Debris, shrapnel
- Death/spawn effects
All particles are created at the same moment but with randomized properties according to the configured ranges.
| Name | Type | Description |
|---|---|---|
quantity |
Int | Number of particles to emit instantly. Must be 1 or greater, does nothing if less. * haxe // Explosion effect emitter.explode(100); * // Small puff of smoke emitter.explode(10); |
stop(): VoidStops particle emission immediately.
Existing particles continue to animate until their lifespan ends. The emitter status changes from EMITTING to SPREADING (if particles remain) or IDLE (if no particles are active).
Safe to call even if not currently emitting.
emitParticle(): VoidEmits a single particle with randomized properties.
This method:
- Gets a particle from the pool
- Randomizes properties within configured ranges
- Initializes position, velocity, and other attributes
- Triggers the emitParticle event
Can be called directly for custom emission patterns beyond the built-in continuous and burst modes.
// Emit particles in a custom pattern
for (i in 0...5) {
emitter.x = i * 50;
emitter.emitParticle();
}
new(): VoidCreates a new ParticleEmitter instance.
The emitter starts in IDLE status and must be activated using
either emitContinuously() for streams or explode() for bursts.
Default settings create white 5x5 pixel particles.
Private Members
| Name | Type |
|---|---|
deg |
Float |
| Returns |
|---|
| Float |
| Name | Type |
|---|---|
a |
Color |
b |
Color |
percent |
Float |
| Returns |
|---|
| Color |
| Name | Type |
|---|---|
angle |
Float |
speed |
Float |
result |
Point |
computeVelocity(velocity: Float, acceleration: Float, drag: Float, max: Float, elapsed: Float): FloatA tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
| Name | Type | Description |
|---|---|---|
velocity |
Float | Any component of velocity (e.g. 20). |
acceleration |
Float | Rate at which the velocity is changing. |
drag |
Float | This is how much the velocity changes if acceleration is not set. |
max |
Float | An absolute value cap for the velocity (0 for no cap). |
elapsed |
Float | The amount of time passed in to the latest update cycle |
| Returns | Description |
|---|---|
| Float | The altered velocity value. |
emitObservedDirty(instance: ParticleEmitter, fromSerializedField: Bool): VoidEvent when any observable value as changed on this instance.
| Name | Type |
|---|---|
instance |
ParticleEmitter |
fromSerializedField |
Bool |
emitEmitParticle(particle: ParticleItem): VoidEmitted when a new particle is launched. Useful for applying custom initialization or effects to particles.
| Name | Type | Description |
|---|---|---|
particle |
ParticleItem | The particle that was just emitted |
emitStatusChange(current: Anonymous, previous: Anonymous): VoidEvent when status field changes.
| Name | Type |
|---|---|
current |
Anonymous |
previous |
Anonymous |
bindAsComponent(): VoidCalled when this emitter is bound as a component to a visual. Currently empty but can be overridden for custom initialization.
Updates the emitter and all active particles.
Called automatically by the game loop. Handles:
- Continuous particle emission timing
- Particle position, velocity, and property updates
- Particle lifecycle and recycling
- Status updates (IDLE, EMITTING, SPREADING)
| Name | Type | Description |
|---|---|---|
delta |
Float | Time elapsed since last update in seconds |
Emits particles based on continuous emission settings.
Accumulates time and emits particles when the interval threshold is reached. Handles quantity countdown and automatic stopping.
| Name | Type | Description |
|---|---|---|
delta |
Float | Time elapsed since last update in seconds |
updateParticle(particle: ParticleItem, delta: Float): VoidUpdates a single particle's properties and visual.
Handles:
- Age progression and lifespan checking
- Property interpolation (velocity, scale, color, etc.)
- Physics simulation (acceleration, drag, max velocity)
- Visual synchronization if enabled
Properties are interpolated linearly over the particle's lifetime when start and end values differ.
| Name | Type | Description |
|---|---|---|
particle |
ParticleItem | The particle to update |
delta |
Float | Time elapsed since last update in seconds |
createParticleItem(): ParticleItemCreates a new ParticleItem instance.
Override this method in a subclass to use custom ParticleItem implementations with additional properties or behavior.
| Returns | Description |
|---|---|
| ParticleItem | A new ParticleItem instance * haxe override function createParticleItem():ParticleItem { return new CustomParticleItem(); } |
getParticle(): ParticleItemGets a particle from the pool or creates a new one.
Implements object pooling for performance:
- Tries to reuse a recycled particle
- Creates new particle if pool is empty
- Assigns or recycles visual
- Adds to active particles list
| Returns | Description |
|---|---|
| ParticleItem | An active particle ready for initialization |
Gets or creates a visual for a particle.
Default implementation creates a 5x5 white quad centered at anchor point.
Override this method or use getCustomParticleVisual callback to
provide custom visuals like sprites, shapes, or complex graphics.
| Name | Type | Description |
|---|---|---|
existingVisual |
Visual | A recycled visual if available, null for new particles |
| Returns | Description |
|---|---|
| Visual | Visual to use for the particle * haxe override function getParticleVisual(existingVisual:Visual):Visual { if (existingVisual != null) { existingVisual.active = true; return existingVisual; } var sprite = new Quad(); sprite.texture = particleTexture; sprite.anchor(0.5, 0.5); return sprite; } |
recycleParticle(particle: ParticleItem): VoidRecycles a particle back to the pool.
Removes particle from active list, recycles its visual, and adds to recycled pool for later reuse. If the visual was destroyed, nullifies the reference.
| Name | Type | Description |
|---|---|---|
particle |
ParticleItem | The particle to recycle |
Recycles a particle's visual for later reuse.
Default implementation simply deactivates the visual. Override to perform custom cleanup like resetting animations, clearing filters, or releasing resources.
| Name | Type | Description |
|---|---|---|
visualToRecycle |
Visual | The visual to recycle |
| Name | Type |
|---|---|
a |
Float |
b |
Float |
| Returns |
|---|
| Float |
| Name | Type |
|---|---|
a |
Color |
b |
Color |
| Returns |
|---|
| Color |
| Name | Type |
|---|---|
entity |
Entity |
getEntity(): Entity| Returns |
|---|
| Entity |
Metadata
| Name | Parameters |
|---|---|
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |
:build |
ceramic.macros.ComponentMacro.build() |
:autoBuild |
ceramic.macros.ComponentMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |