class SFML::ParticleSystem

A pool-backed particle emitter built on top of SFML::VertexArray. Each particle is two triangles (a quad) so a single CSFML draw call ships thousands at once.

class Sparks < SFML::ParticleSystem def emit_one angle = rand(0.0..2 * Math::PI) speed = rand(80.0..200.0) spawn( position: @origin, velocity: SFML::Vector2.new(Math.cos(angle), Math.sin(angle)) * speed, lifetime: 0.8, color: SFML::Color.new(255, 200, 50), size: 4, ) end end

sparks = Sparks.new(max: 500)

def update(dt) 5.times { sparks.emit_one } if mouse_down? sparks.update(dt) end

def draw window.draw(sparks) end

Particles fade linearly from full alpha at spawn to zero alpha at lifetime. Override update_particle(p, dt) to apply gravity, drag, custom colour curves, etc.

Acceleration: pass gravity: to the constructor for the common case (px/s² added to velocity every frame). For richer behaviour, subclass and override.