flow: transient particles, isomorphic afterDeathTickers, setPosition

This commit is contained in:
cha0s 2019-11-03 13:25:25 -06:00
parent 3153c29d4d
commit e80f38369f
3 changed files with 21 additions and 14 deletions

View File

@ -148,9 +148,11 @@ export class Alive extends decorate(Trait) {
this._context
)
this._dyingTickingPromise.then(() => {
this.entity.emit('died');
const diedPromises = this.entity.invokeHookFlat('died');
Promise.all(diedPromises).then(() => {
this.entity.destroy();
});
});
},
};

View File

@ -25,6 +25,7 @@ export class Emitted extends decorate(Trait) {
start: 1,
end: 1,
},
transient: true,
ttl: 2,
velocity: [0, 0],
};
@ -49,6 +50,10 @@ export class Emitted extends decorate(Trait) {
this.velocity = new Vector.Range(this.params.velocity);
}
get isTransientParticle() {
return !!this.params.transient;
}
methods() {
return {

View File

@ -28,11 +28,13 @@ export class Emitter extends decorate(Trait) {
}
onParticleDead(particle) {
if (particle.isTransientParticle) {
particle.body.destroy();
}
}
onParticleUpdate(particle) {
particle.body.position = [particle.p.x, particle.p.y];
particle.body.setPosition([particle.p.x, particle.p.y]);
particle.body.opacity = particle.alpha;
particle.body.visibleScale = [particle.scale, particle.scale];
particle.body.rotation = particle.rotation * PI_180;
@ -40,7 +42,6 @@ export class Emitter extends decorate(Trait) {
hooks() {
const hooks = {};
if (AVOCADO_CLIENT) {
hooks.afterDestructionTickers = () => {
return (elapsed) => {
this.tick(elapsed);
@ -50,7 +51,6 @@ export class Emitter extends decorate(Trait) {
}
};
};
}
return hooks;
}