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,8 +148,10 @@ export class Alive extends decorate(Trait) {
this._context
)
this._dyingTickingPromise.then(() => {
this.entity.emit('died');
this.entity.destroy();
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) {
particle.body.destroy();
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,17 +42,15 @@ export class Emitter extends decorate(Trait) {
hooks() {
const hooks = {};
if (AVOCADO_CLIENT) {
hooks.afterDestructionTickers = () => {
return (elapsed) => {
this.tick(elapsed);
if (0 === this.emitter.particles.length) {
this.emitter.destroy();
return true;
}
};
hooks.afterDestructionTickers = () => {
return (elapsed) => {
this.tick(elapsed);
if (0 === this.emitter.particles.length) {
this.emitter.destroy();
return true;
}
};
}
};
return hooks;
}