UNPKG

duckengine

Version:
196 lines (195 loc) 7.04 kB
import { Duck } from '../../../index'; import Game from '../../game'; import Particle from './particle'; import Scene from '../../scene'; /** * @class ParticleEmitter * @classdesc Creates a DuckEngine ParticleEmitter * @description The ParticleEmitter Class. Emits, creates, and destroys particles * @since 1.0.0-beta */ export default class ParticleEmitter { /** * @memberof ParticleEmitter * @description A unique identifier for the ParticleEmitter * @type string * @since 1.0.0-beta */ readonly id: string; protected particle: Particle; /** * @memberof ParticleEmitter * @description A range of numbers where particle x pos will be * @type Duck.Types.ParticleEmitter.Range * @since 1.0.0-beta */ rangeX: Duck.Types.ParticleEmitter.Range; /** * @memberof ParticleEmitter * @description A range of numbers where particle y pos will be * @type Duck.Types.ParticleEmitter.Range * @since 1.0.0-beta */ rangeY: Duck.Types.ParticleEmitter.Range; /** * @memberof ParticleEmitter * @description The starting amount of particle * @type number * @since 1.0.0-beta */ readonly amount: number; /** * @memberof ParticleEmitter * @description The list of current particles * @type Particles[] * @since 1.0.0-beta */ list: Particle[]; /** * @memberof ParticleEmitter * @description Game instance * @type Game * @since 1.0.0-beta */ game: Game; /** * @memberof ParticleEmitter * @description Scene instance * @type Scene * @since 1.0.0-beta */ scene: Scene; /** * @memberof ParticleEmitter * @description Determines if the ParticleEmitter is emitting or not * @type boolean * @since 1.0.0-beta */ emitting: boolean; /** * @memberof ParticleEmitter * @description Determines if the ParticleEmitter is enabled or not * @type boolean * @since 2.0.0 */ enabled: boolean; protected floatRangeX: Duck.Types.ParticleEmitter.Range; protected floatRangeY: Duck.Types.ParticleEmitter.Range; /** * @constructor ParticleEmitter * @description Creates ParticleEmitter instance * @param {Particle} particle Base particle that is cloned and modified from * @param {Duck.Types.ParticleEmitter.Range} rangeX Where the new emitted particles x position is. A range of 2 values * @param {Duck.Types.ParticleEmitter.Range} rangeY Where the new emitted particles y position is. A range of 2 values * @param {number} amount Amount of starting particles * @param {boolean} [autoCreate=true] Determines if particles are created on init, populates the list, optional -> defaults: true * @param {Game} game Game instance * @param {Scene} scene Scene instance * @since 1.0.0-beta */ constructor(particle: Particle, rangeX: Duck.Types.ParticleEmitter.Range, rangeY: Duck.Types.ParticleEmitter.Range, amount: number, game: Game, scene: Scene, autoCreate?: boolean); /** * @memberof ParticleEmitter * @description Creates an amount of particles * @since 2.1.0 */ create(): void; /** * @memberof ParticleEmitter * @description Creates one particle * @since 2.1.0 */ createOne(): void; /** * @memberof ParticleEmitter * @description Starts emitting particles * @since 1.0.0-beta */ emit(): void; /** * @memberof ParticleEmitter * @description Stops emitting particles * @since 1.0.0-beta */ stopEmit(): void; /** * @memberof ParticleEmitter * @description Starts emitting particles for a certain duration * @param {number} ms Duration in milliseconds * @since 1.0.0-beta */ emitFor(ms: number): void; /** * @memberof ParticleEmitter * @description Sets the new or old particles' position range * @param {Duck.Types.ParticleEmitter.Range} rangeX Where the new emitted particles x position is. A range of 2 values * @param {Duck.Types.ParticleEmitter.Range} rangeY Where the new emitted particles y position is. A range of 2 values * @since 1.0.0-beta */ setRange(rangeX: Duck.Types.ParticleEmitter.Range, rangeY: Duck.Types.ParticleEmitter.Range): void; /** * @memberof ParticleEmitter * @description Spawns new particles after the initial particles * @param {number} intervalMS How often a new particle gets spawned * @param {number} [limitTo] A limit to how many particles can be rendered at once, optional * @since 1.0.0-beta */ keepEmitting(intervalMS: number, limitTo?: number): void; /** * @memberof ParticleEmitter * @description Pops particles from the list if too many particles exist * @since 1.0.0 */ offloadMaxAmount(limit: number): void; /** * @memberof ParticleEmitter * @description Offloads particles based on position * @param {number} bounds The Bounds of the particles, a BoundsLike object that causes a particle to be offloaded * @since 2.0.0 */ offloadBounds(bounds: Duck.Types.Math.BoundsLike): void; /** * @memberof ParticleEmitter * @description Offloads particles based on how many seconds they existed for * @param {number} ageInSeconds Max amount of seconds a particle existed for * @since 1.0.0 */ offloadMaxAge(ageInSeconds: number): void; /** * @memberof ParticleEmitter * @description Sets the velocity of all particles * @param {'x'|'y'} axis 'x' or 'y' axis to change the velocity of all particles * @param {number} v Value to set the velocity of all particles * @since 1.0.0-beta */ setVelocity(axis: 'x' | 'y', v: number): void; /** * @memberof ParticleEmitter * @description Wobbles the particle on a random direction and axis * @param {number} v Value to set the wobble velocity to * @since 1.0.0-beta */ wobble(v: number): void; /** * @memberof ParticleEmitter * @description Sets the floatVelocity of all particles in between a range * @param {Duck.Types.ParticleEmitter.Range} rangeVX A range of 2 values for the floatVelocity.x, randomly chosen between that range * @param {Duck.Types.ParticleEmitter.Range} rangeVY A range of 2 values for the floatVelocity.y, randomly chosen between that range * @since 1.0.0-beta */ float(rangeVX: Duck.Types.ParticleEmitter.Range, rangeVY: Duck.Types.ParticleEmitter.Range): void; /** * @memberof ParticleEmitter * @description Sets the fillColor of all particles * @param {string} fillColor Color * @since 1.0.0-beta */ setFillColor(fillColor: string): void; /** * @memberof ParticleEmitter * @description Sets the imagePath of all particles * @param {string} imagePath Image path * @since 1.0.0 */ setImagePath(imagePath: string): void; }