xxxxxxxxxx
55
class Emitter {
constructor(x, y, icons) {
this.origin = createVector(x, y);
this.particles = [];
this.icons = icons; // Store the icons array
this.maxParticles = 50; // Limit the number of particles
}
addParticle() {
if (this.particles.length < this.maxParticles) {
this.particles.push(new Particle(this.origin.x, this.origin.y, this.icons));
}
}
run() {
// Looping through backwards to delete
for (let i = this.particles.length - 1; i >= 0; i--) {
this.particles[i].run();
if (this.particles[i].isDead()) {
// Remove the particle
this.particles.splice(i, 1);
}
}
}
}
/*
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
class Emitter {
constructor(x, y) {
this.origin = createVector(x, y);
this.particles = [];
}
addParticle() {
this.particles.push(new Particle(this.origin.x, this.origin.y));
}
run() {
// Looping through backwards to delete
for (let i = this.particles.length - 1; i >= 0; i--) {
this.particles[i].run();
if (this.particles[i].isDead()) {
// Remove the particle
this.particles.splice(i, 1);
}
}
}
}
*/