Bash.tv → GitHub → itch.io

Particle Engine

Fast reusable effects (explosions, sparks, smoke, dust, confetti) with a fixed memory budget, so effects never slow the game by piling up.

Files: particle-engine.js (the component, no dependencies) and particle-engine.test.mjs (7 tests). Copy particle-engine.js into your game, for example to src/components/, and import it as an ES module.

Usage

import { createParticles, PRESETS } from "./particle-engine.js";
const fx = createParticles({ max: 800 });
fx.emit(enemy.x, enemy.y, "explosion");                       // a preset
fx.emit(x, y, { ...PRESETS.sparks, colors: ["#fff"] }, 12);   // or your own settings
function frame(dt) { fx.update(dt); fx.draw(ctx); }

API

PRESETS: explosion, sparks, smoke, dust, confetti, trail

Engines

Engine Notes
Vanilla / Canvas 2D draw(ctx) does everything.
Phaser use Phaser’s particle emitters, or run this and draw with forEach into a Graphics object.
PixiJS run update(), then forEach into a ParticleContainer of sprites (reuse sprites by index).
Three.js run update(), then forEach into a Points geometry’s position and color buffers.

Tests

Node tests: presets, the max budget, life and fading, gravity, scale, forEach output, draw calls, seeded randomness.

Run them with node --test toolkit/components/particle-engine/ (Node 20 or newer, nothing to install).