fix: only tick emitter on client and wait to remove tick handler until after destroy finishes
This commit is contained in:
parent
1f065d58e3
commit
0710ff875d
|
@ -9,14 +9,10 @@ export class Emitter extends decorate(Trait) {
|
|||
|
||||
initialize() {
|
||||
this.emitters = {};
|
||||
this.ticker = new Ticker(1 / 10);
|
||||
this.ticker.on('tick', (elapsed) => {
|
||||
this.updateFrequency();
|
||||
for (const key in this.emitters) {
|
||||
const emitter = this.emitters[key];
|
||||
emitter.tick(elapsed);
|
||||
}
|
||||
});
|
||||
if (AVOCADO_CLIENT) {
|
||||
this.ticker = new Ticker(1 / 10);
|
||||
this.ticker.on('tick', this.onTick, this);
|
||||
}
|
||||
}
|
||||
|
||||
static addEmitter(emitter) {
|
||||
|
@ -46,6 +42,14 @@ export class Emitter extends decorate(Trait) {
|
|||
this._emitters.splice(index, 1);
|
||||
}
|
||||
|
||||
onTick(elapsed) {
|
||||
this.updateFrequency();
|
||||
for (const key in this.emitters) {
|
||||
const emitter = this.emitters[key];
|
||||
emitter.tick(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
updateFrequency() {
|
||||
const particleCount = this.constructor.particleCount();
|
||||
const updatesPerSecond = Math.max(15, (60 - (particleCount / 10)));
|
||||
|
@ -61,6 +65,7 @@ export class Emitter extends decorate(Trait) {
|
|||
const emitter = this.emitters[key];
|
||||
this.ticker.tick(elapsed);
|
||||
if (!emitter.hasParticles()) {
|
||||
this.ticker.off('tick', this.onTick);
|
||||
emitter.destroy();
|
||||
this.constructor.removeEmitter(emitter);
|
||||
delete this.emitters[key];
|
||||
|
@ -105,7 +110,9 @@ export class Emitter extends decorate(Trait) {
|
|||
}
|
||||
|
||||
tick(elapsed) {
|
||||
this.ticker.tick(elapsed);
|
||||
if (AVOCADO_CLIENT) {
|
||||
this.ticker.tick(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user