Short-lived sprites — sparks, debris, smoke — with a cap on how many exist at once.
particles =
Cauldron2D.Particles.new(300)
|> Cauldron2D.Particles.spawn([%{art: :spark, pos: {x, y}, vel: {vx, vy}, ttl: 0.4}])
|> Cauldron2D.Particles.step(dt, fields: gravity, drag: 0.5)
Cauldron2D.Particles.movers(particles, {-0.5, -0.5})A particle is %{art: art, pos: {x, y}, vel: {vx, vy}, ttl: seconds}. When spawning
would exceed the cap, the oldest particles go first.
Summary
Functions
How many particles are alive.
The particles as {art, {x, y}} movers, oldest first, each position shifted by offset.
An empty set holding at most cap particles.
Add particles, dropping the oldest when the cap is exceeded.
Move every particle for dt seconds and drop those whose time is up.
Types
@type particle() :: %{ art: term(), pos: Cauldron2D.Body.point(), vel: Cauldron2D.Body.point(), ttl: number() }
@type t() :: %Cauldron2D.Particles{cap: pos_integer(), items: [particle()]}
Functions
@spec count(t()) :: non_neg_integer()
How many particles are alive.
@spec movers(t(), Cauldron2D.Body.point()) :: [{term(), Cauldron2D.Body.point()}]
The particles as {art, {x, y}} movers, oldest first, each position shifted by offset.
The offset is what turns a particle's centre into the top-left corner a sprite is drawn
from; {-0.5, -0.5} centres a one-tile sprite.
@spec new(pos_integer()) :: t()
An empty set holding at most cap particles.
Add particles, dropping the oldest when the cap is exceeded.
Move every particle for dt seconds and drop those whose time is up.
Options
:fields— gravity fields asCauldron2D.Body.gravitate/3takes. Default[]:drag— a coefficient asCauldron2D.Body.drag/3takes. Default0