refactor: velocity as polar

This commit is contained in:
cha0s 2019-11-09 16:44:45 -06:00
parent ba601af505
commit a0f5c0019e
2 changed files with 21 additions and 9 deletions

View File

@ -28,7 +28,10 @@ export class Emitted extends decorate(Trait) {
}, },
transient: true, transient: true,
ttl: 2, ttl: 2,
velocity: [0, 0], velocity: {
angle: 0,
magnitude: 0,
},
}; };
} }
@ -53,7 +56,8 @@ export class Emitted extends decorate(Trait) {
this.scaleStart = new Range(this.params.scale.start); this.scaleStart = new Range(this.params.scale.start);
this.scaleEnd = new Range(this.params.scale.end); this.scaleEnd = new Range(this.params.scale.end);
this.ttl = this.params.ttl; this.ttl = this.params.ttl;
this.velocity = new Vector.Range(this.params.velocity); this.velocityAngle = new Range(this.params.velocity.angle);
this.velocityMagnitude = new Range(this.params.velocity.magnitude);
} }
get isTransientParticle() { get isTransientParticle() {
@ -65,7 +69,6 @@ export class Emitted extends decorate(Trait) {
particle: () => { particle: () => {
const position = null === this.position ? null : this.position.value(); const position = null === this.position ? null : this.position.value();
const velocity = this.velocity.value();
const force = this.force.value(); const force = this.force.value();
return { return {
alpha: { alpha: {
@ -85,7 +88,10 @@ export class Emitted extends decorate(Trait) {
end: this.scaleEnd.value(), end: this.scaleEnd.value(),
}, },
ttl: this.ttl, ttl: this.ttl,
velocity, velocity: {
angle: this.velocityAngle.value(),
magnitude: this.velocityMagnitude.value(),
},
}; };
}, },

View File

@ -46,13 +46,18 @@ export class Emitter extends decorate(Trait) {
} }
} }
for (const key in this.params.particles) { for (const key in this.params.particles) {
particles[key] = this.params.particles[key]; if (particles[key]) {
particles[key] = merge({}, particles[key], this.params.particles[key]);
}
else {
particles[key] = this.params.particles[key];
}
} }
this.particles = particles; this.particles = particles;
} }
onParticleDead(particle) { onParticleDead(particle) {
if (particle.isTransientParticle) { if (particle.body.isTransientParticle) {
particle.body.destroy(); particle.body.destroy();
} }
} }
@ -107,8 +112,9 @@ export class Emitter extends decorate(Trait) {
new Proton.Mass(particle.mass), new Proton.Mass(particle.mass),
new Proton.Life(particle.ttl), new Proton.Life(particle.ttl),
new Proton.Velocity( new Proton.Velocity(
particle.velocity[0], particle.velocity.magnitude,
particle.velocity[1] particle.velocity.angle,
'polar'
), ),
]; ];
const behaviors = [ const behaviors = [
@ -160,7 +166,7 @@ export class Emitter extends decorate(Trait) {
let { let {
count = 1, count = 1,
rate = 0, rate = 0,
} = order; } = mergedJson;
if (0 === rate) { if (0 === rate) {
for (let i = 0; i < count; ++i) { for (let i = 0; i < count; ++i) {
this.entity.emitParticleJson(mergedJson); this.entity.emitParticleJson(mergedJson);