1681-engine / index / ParticleSim
Class: ParticleSim ​
Defined in: src/particles/ParticleSim.ts:10
The particles of one emitter as flat typed arrays (structure of arrays): position, velocity, age and lifetime, rotation and spin, and a per-particle random draw the curves can use. Pure, no Pixi: the emitter draws what this holds, and tests step it under node.
Live particles are packed at indices 0 … count - 1. A particle that dies is replaced by the last live one, so a step never leaves holes and never allocates; the order of particles is therefore not stable, which drawing does not need (every live index is written again each frame).
Constructors ​
Constructor ​
new ParticleSim(capacity): ParticleSim;Defined in: src/particles/ParticleSim.ts:23
Parameters ​
| Parameter | Type |
|---|---|
capacity | number |
Returns ​
ParticleSim
Properties ​
age ​
readonly age: Float32Array;Defined in: src/particles/ParticleSim.ts:15
capacity ​
readonly capacity: number;Defined in: src/particles/ParticleSim.ts:23
count ​
count: number = 0;Defined in: src/particles/ParticleSim.ts:21
life ​
readonly life: Float32Array;Defined in: src/particles/ParticleSim.ts:16
rot ​
readonly rot: Float32Array;Defined in: src/particles/ParticleSim.ts:17
seed ​
readonly seed: Float32Array;Defined in: src/particles/ParticleSim.ts:20
A random draw per particle (0–1), fixed for its life: size variance, flicker phase.
spin ​
readonly spin: Float32Array;Defined in: src/particles/ParticleSim.ts:18
vx ​
readonly vx: Float32Array;Defined in: src/particles/ParticleSim.ts:13
vy ​
readonly vy: Float32Array;Defined in: src/particles/ParticleSim.ts:14
x ​
readonly x: Float32Array;Defined in: src/particles/ParticleSim.ts:11
y ​
readonly y: Float32Array;Defined in: src/particles/ParticleSim.ts:12
Methods ​
clear() ​
clear(): number;Defined in: src/particles/ParticleSim.ts:86
Every particle gone; returns how many there were.
Returns ​
number
progress() ​
progress(i): number;Defined in: src/particles/ParticleSim.ts:81
The share of its life particle i has lived (0–1).
Parameters ​
| Parameter | Type |
|---|---|
i | number |
Returns ​
number
spawn() ​
spawn(
x,
y,
vx,
vy,
life,
rot,
spin,
seed
): number;Defined in: src/particles/ParticleSim.ts:36
Adds a particle; returns its index, or -1 when the sim is full. life is in seconds.
Parameters ​
| Parameter | Type |
|---|---|
x | number |
y | number |
vx | number |
vy | number |
life | number |
rot | number |
spin | number |
seed | number |
Returns ​
number
step() ​
step(
dt,
gravityX,
gravityY,
drag
): number;Defined in: src/particles/ParticleSim.ts:56
Advances every particle by dt seconds: gravity (px/s²) added to velocity, then drag, then position. Drag is the share of speed lost per second, applied as exp(-drag × dt) so it is the same at any frame rate. Returns how many particles died this step.
Parameters ​
| Parameter | Type |
|---|---|
dt | number |
gravityX | number |
gravityY | number |
drag | number |
Returns ​
number