Skip to content

particles

Types

ParticleEmitter

The particle emitter component defines how particles are spawned and their initial properties.

FieldTypeDescription
activebooleanWhether the emitter is active and should spawn particles
spawnRatenumberNumber of particles to spawn per second
accumulatornumberInternal timer to track spawning intervals
anglenumberBase angle (in degrees) for particle emission
spreadnumberAngle spread (in degrees) for randomizing particle emission direction
speedMinnumberMinimum initial speed of particles
speedMaxnumberMaximum initial speed of particles
lifeMinnumberMinimum lifetime of particles in seconds
lifeMaxnumberMaximum lifetime of particles in seconds
spriteany|nilOptional sprite to use for particles
colorstable|nilOptional list of colors for particles to cycle through over their lifetime
charstable|nilOptional list of characters for particles to cycle through over their lifetime
bgColorstable|nilOptional list of background blit chars for particles over their lifetime
znumberRender layer for particles (default 1)
bouncebooleanWhether particles should bounce off solid tiles
gravityScalenumberMultiplier for how much gravity affects the particle (0 for no gravity)
dragnumberLinear drag coefficient to slow down particles over time (0 for no drag)

ParticlesModule

The main particles module with functions to create emitters and systems.

Methods

particles.createEmitter(config)

Create a particle emitter instance from a config table.

  • config (table) Configuration parameters for the emitter

  • returns emitter (ParticleEmitter) The created emitter instance

particles.load(path)

Load an emitter config from a file and create an emitter instance.

  • path (string) Path to the emitter config file

  • returns emitter (ParticleEmitter|nil) The created emitter instance, or nil if loading failed

particles.emitterSystem(scene)

Create an emitter system for the ECS. This system will spawn particles according to the emitter's configuration.

  • scene (SceneInstance) The scene to which the system will be added

  • returns fn (fun(dt:number, ids:table, components:table)) The emitter system function to be called each update

particles.motionSystem(scene)

Create a motion system for particles. This system applies velocity to position, gravity, drag, and optional bouncing.

  • scene (SceneInstance) The scene to which the system will be added

  • returns fn (fun(dt:number, ids:table, components:table)) The motion system function to be called each update

particles.updateSystem(scene)

Create an update system for particles (color/char progress).

  • scene (SceneInstance) The scene to which the system will be added

  • returns fn (fun(dt:number, ids:table, components:table)) The update system function to be called each update

particles.cleanupSystem(scene)

Create a cleanup system that destroys expired particles.

  • scene (SceneInstance) The scene to which the system will be added

  • returns fn (fun(dt:number, ids:table, components:table)) The cleanup system function to be called each update

particles.registerAll(scene)

Register particle systems on the given scene.

  • scene (SceneInstance) The scene to which the systems will be added

Last updated:

Released under the MIT License.