Skip to content

ParticleEmitter

namespace Griff.Scenes;
public sealed class ParticleEmitter : Component, IDrawable

Sprays small fading quads: smoke, sparks, dust, explosions. Particles live in world space, so a moving emitter leaves a trail. Call Burst from a script for one-off effects, or use BurstOnStart with DestroyWhenFinished in a prefab and spawn it.

Live particles aren’t saved, so rewinding during play clears them.

This is a component: its saved properties are on its component page.

public bool AnimateFrames { get; set; }

With Frames: each particle shows them in order, one after another across its life, instead of one picked at birth.

public int BurstOnStart { get; set; }

Particles emitted at once when the game first runs this emitter (e.g. for an explosion prefab).

public int Columns { get; set; }

For sprite sheets: frames across the image, as on a Sprite. 1 for a single image.

public bool DestroyWhenFinished { get; set; }

Removes the entity once it has stopped emitting and its last particle is gone.

public float Direction { get; set; }

Degrees: 0 is right, 90 is up. The entity’s rotation is added.

public bool Emitting { get; set; }

While set, emits Rate particles per second.

public Color EndColor { get; set; }

Each particle’s color at the end of its life, blending from StartColor; a clear one fades it out.

public float EndSize { get; set; }

Width and height in world units at the end of its life.

public int Frame { get; set; }

Which frame of the sheet each particle shows, counting left to right, top to bottom from 0. Frames takes over when it’s set.

public IReadOnlyList<int> FrameList { get; }

The frames Frames names, in order; empty when it names none.

public string? Frames { get; set; }

Frames to use instead of Frame, written like an Animation clip’s: 0-1 is frames 0 and 1, 3-4, 7 is 3, 4 and 7, and 3-0 runs backward. Each particle picks one at random as it’s born (from the game’s random, so a rewound or networked game repeats), or with AnimateFrames steps through them.

public float GravityScale { get; set; }

Multiplier on world gravity; 0 floats, 1 falls like a body.

public string? Image { get; set; }

Image for each particle, relative to Assets. Without one, particles are solid squares.

public bool IsFinished { get; }

True once there’s nothing left to show: the start burst has happened, the emitter isn’t emitting continuously, and every particle has died.

public float Lifetime { get; set; }

Seconds each particle lives.

public int MaxParticles { get; set; }

The oldest particles make room for new ones beyond this many.

public int Order { get; set; }

Higher draws on top, like Order.

public IReadOnlyList<Particle> Particles { get; }

The live particles, oldest first.

public float Rate { get; set; }

Particles per second while Emitting.

public int Rows { get; set; }

For sprite sheets: frames down the image.

public float Speed { get; set; }

Starting speed in world units per second.

public float SpeedVariation { get; set; }

How much each particle’s speed may differ, from 0 (all the same) to 1 (anywhere from 0 to double).

public float Spread { get; set; }

Width of the spray in degrees around Direction; 360 sprays every way.

public Color StartColor { get; set; }

Each particle’s color when it’s made.

public float StartSize { get; set; }

Width and height in world units at birth.

public void Advance(float seconds, Vector2 gravity)

Ages and moves particles and emits new ones. Called by the game every frame.

public void Burst(int count)

Emits count particles right away.

public void Clear()

Removes every live particle.

public Color ColorAt(float progress)

The color of a particle at progress through its life.

public int FrameOf(Particle particle, float progress)

The frame a particle shows at progress through its life.

public Vector4 FrameRect(int frame)

The part of the image to show for frame: (u, v, width, height) in 0–1 image space, as FrameRect.

public static int[] ParseFrames(string? text)

Reads frames written like Frames; entries that don’t make sense are skipped.

public IEnumerable<SpriteDraw> ParticleDraws()

One quad per live particle, in world space at the emitter’s depth, where they are now.

public IEnumerable<SpriteDraw> ParticleDraws(StepBlend blend)

One quad per live particle, in world space at the emitter’s depth, in a frame drawn as blend says: each between where it was and is (and how old it was and is), if they moved in the last step.

public float SizeAt(float progress)

The size of a particle at progress through its life.