Explosions, smoke, sparks, dust, trails, confetti, rain, magic and environmental effects. A pooled Canvas 2D particle system with bursts and continuous emitters, ranges for speed, angle, life, size and color, gravity and drag, size, alpha and color over life, additive blending, shapes and sprites, a global cap, and ready presets, plus guidance for GPU particles in Pixi, Phaser and three.js and ...
Download skill (.zip) Files on GitHubParticle effects
Drop-in: assets/particles.js (tests: burst counts, cap and dropped count, life, pooling, emitter rate and duration, drawing
restores blend state; rendered in a browser).
import { Particles, PRESETS } from "./core/particles.js";
const fx = new Particles({ max: 1500, rng: rng.next });
fx.burst(enemy.x, enemy.y, PRESETS.explosion);
fx.burst(player.x, player.y + 12, PRESETS.dust, 4); // footstep (from an animation event)
fx.burst(x, y, { ...PRESETS.sparks, angle: [hitAngle - 0.6, hitAngle + 0.6] }); // directional
const trail = fx.emitter({ ...PRESETS.trail, x: rocket.x, y: rocket.y }); // move it: trail.x = rocket.x; trail.stop()
const rain = fx.emitter({ ...PRESETS.rain, x: cam.x, y: cam.top - 20, spreadX: cam.w });
// update: fx.update(dt) draw (world space): fx.draw(ctx)
Presets: explosion, smoke, sparks, dust, hit, trail, confetti, rain, magic. Every field is a number or a
[min, max] range; colors is a gradient over life; sizeEnd/alphaEnd are end values; blend: "lighter" for glow.
Make effects read well
- Layer a big effect from small ones: flash (1 frame) + core burst (fast, bright, additive) + smoke (slow, dark) + sparks + shake.
- Short lives (0.2–0.8 s) for feedback; long lives only for ambience.
- Direction tells a story: sparks fly away from the hit, dust kicks backward from the feet.
- Keep gameplay readable: particles behind bullets and enemies, lower alpha on frequent effects, fewer during busy fights.
- Respect reduced motion: fewer and calmer particles.
Performance
- Canvas 2D: a cap of ~1,000–2,000 particles on phones. Squares are cheapest, circles next,
lighterblending costs more. Pre-rendered glow sprites (sprite: canvas) beat drawing gradients per particle. - Lots more (10k+): GPU particles. Pixi
ParticleContainer, Phaser particle emitters, three.jsPointsorInstancedMeshwith a shader (webgl-performance). - Scale counts by quality setting:
fx.burst(x, y, preset, Math.round(preset.count * quality)).