Skip to content

Particles

Marc Flerackers edited this page Jun 23, 2024 · 4 revisions

Particles is a component so that transformation can be optimized and all particles can be drawn at once.

Particles has options for the emitter and the particles. The emitter decides where, how and when particles are emitted. An emitter can emit particles periodically or instantly using the emit command. Once emitted, the particle options will decide how the particle looks, moves and how long it lives.

export type ParticlesOpt = {
    maxParticles: number;
    emitterShape?: ShapeType;
    emitterLifetime?: number;
    emissionRate: number;
    emissionDirection: number;
    emissionSpread: number;
    particleLifeTime: [number, number];
    particleSpeed: [number, number];
    particleColors?: Color[];
    particleOpacities?: number[];
    particleSprites?: string[];
};

export interface ParticlesComp extends Comp {
    emit(n: number): void;
    onEnd(cb: () => void): void;
}

export function particles(opt: ParticlesOpt): ParticlesComp

If needed a separate emitter component can be made to emit particles as objects. However this will have worse performance and as such should not be encouraged.

Clone this wiki locally