import Container from "./../renderable/container.js"; import { type ParticleEmitterSettings } from "./settings.ts"; /** * Particle Emitter Object. * * ### Blend modes * * An emitter draws no pixels of its own: every {@link Particle} is a * renderable in its own right and carries its own blend mode. Assigning * `emitter.blendMode` applies the mode to the particles — both the ones * already alive and, through {@link ParticleEmitterSettings.blendMode}, the * ones emitted afterwards. The change is picked up on the emitter's next * `update`, so within the same frame. * * ```js * emitter.blendMode = "overlay"; // live particles AND future ones * ``` * * ### Reference space * * A particle stores a position, and * {@link ParticleEmitterSettings.referenceSpace} decides what that position is * measured against. By default it is the emitter, so a moving emitter carries * its whole cloud along — right for a flame or an aura, wrong for anything * emitted and then abandoned. Set it to `"world"` and the position names a * place in the level instead, so the emitter moves away and leaves the * particles behind; that is a trail. Pass a {@link Container} to measure from * something else entirely. * * Changing it at runtime — by assigning the property or through * {@link ParticleEmitter#reset} — re-bases the particles already alive, so the * cloud does not jump; only its subsequent motion changes. * * Two things are worth knowing before reaching for a non-local space. The * emitter is treated as always visible while it has live particles, because * otherwise a trail would vanish the moment the emitter that made it scrolled * off-screen (the particles themselves are still culled individually). And * `clipping` or a `backgroundColor` on the emitter would be applied in the * emitter's own frame rather than the particles', so neither composes with * this. * * ```js * // exhaust that stays where it was emitted * const emitter = new ParticleEmitter(x, y, { referenceSpace: "world" }); * ``` * @category Particles */ export default class ParticleEmitter extends Container { #private; /** * the current (active) emitter settings (with defaults merged in) */ settings: ParticleEmitterSettings; /** * @param x - x position of the particle emitter * @param y - y position of the particle emitter * @param [settings=ParticleEmitterSettings] - the settings for the particle emitter. * @example * // Create a particle emitter at position 100, 100 * let emitter = new ParticleEmitter(100, 100, { * width: 16, * height : 16, * tint: "#f00", * totalParticles: 32, * angle: 0, * angleVariation: 6.283185307179586, * maxLife: 5, * speed: 3 * }); * * // Add the emitter to the game world * app.world.addChild(emitter); * * // Launch all particles one time and stop, like an explosion * emitter.burstParticles(); * * // Launch constantly the particles, like a fountain * emitter.streamParticles(); * * // At the end, remove emitter from the game world * // call this in onDestroyEvent function * app.world.removeChild(emitter); */ constructor(x: number, y: number, settings?: Partial); reset(settings?: Partial): void; /** * What a particle's position is measured against — see * {@link ParticleEmitterSettings.referenceSpace}. * * Assigning this re-bases every particle already alive into the new frame, * so nothing jumps: the cloud stays exactly where it is on screen and only * its subsequent motion differs. Passing it through * {@link ParticleEmitter#reset} does the same. * @default "local" * @example * emitter.referenceSpace = "world"; // start leaving a trail */ get referenceSpace(): "local" | "world" | Container; set referenceSpace(space: "local" | "world" | Container); /** * returns a random point on the x axis within the bounds of this emitter * @returns a random x position within the emitter bounds */ getRandomPointX(): number; /** * returns a random point on the y axis within the bounds this emitter * @returns a random y position within the emitter bounds */ getRandomPointY(): number; /** * Emitter is of type stream and is launching particles * @returns Emitter is Stream and is launching particles */ isRunning(): boolean; /** * Launch particles from emitter constantly (e.g. for stream) * @param [duration] - time that the emitter releases particles in ms */ streamParticles(duration?: number): void; /** * Stop the emitter from generating new particles (used only if emitter is Stream) */ stopStream(): void; /** * Launch all particles from emitter and stop (e.g. for explosion) * @param [total] - number of particles to launch */ burstParticles(total?: number): void; } //# sourceMappingURL=emitter.d.ts.map