refactor: velocity as polar
This commit is contained in:
parent
ba601af505
commit
a0f5c0019e
|
@ -28,7 +28,10 @@ export class Emitted extends decorate(Trait) {
|
|||
},
|
||||
transient: true,
|
||||
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.scaleEnd = new Range(this.params.scale.end);
|
||||
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() {
|
||||
|
@ -65,7 +69,6 @@ export class Emitted extends decorate(Trait) {
|
|||
|
||||
particle: () => {
|
||||
const position = null === this.position ? null : this.position.value();
|
||||
const velocity = this.velocity.value();
|
||||
const force = this.force.value();
|
||||
return {
|
||||
alpha: {
|
||||
|
@ -85,7 +88,10 @@ export class Emitted extends decorate(Trait) {
|
|||
end: this.scaleEnd.value(),
|
||||
},
|
||||
ttl: this.ttl,
|
||||
velocity,
|
||||
velocity: {
|
||||
angle: this.velocityAngle.value(),
|
||||
magnitude: this.velocityMagnitude.value(),
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
@ -46,13 +46,18 @@ export class Emitter extends decorate(Trait) {
|
|||
}
|
||||
}
|
||||
for (const key in this.params.particles) {
|
||||
if (particles[key]) {
|
||||
particles[key] = merge({}, particles[key], this.params.particles[key]);
|
||||
}
|
||||
else {
|
||||
particles[key] = this.params.particles[key];
|
||||
}
|
||||
}
|
||||
this.particles = particles;
|
||||
}
|
||||
|
||||
onParticleDead(particle) {
|
||||
if (particle.isTransientParticle) {
|
||||
if (particle.body.isTransientParticle) {
|
||||
particle.body.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -107,8 +112,9 @@ export class Emitter extends decorate(Trait) {
|
|||
new Proton.Mass(particle.mass),
|
||||
new Proton.Life(particle.ttl),
|
||||
new Proton.Velocity(
|
||||
particle.velocity[0],
|
||||
particle.velocity[1]
|
||||
particle.velocity.magnitude,
|
||||
particle.velocity.angle,
|
||||
'polar'
|
||||
),
|
||||
];
|
||||
const behaviors = [
|
||||
|
@ -160,7 +166,7 @@ export class Emitter extends decorate(Trait) {
|
|||
let {
|
||||
count = 1,
|
||||
rate = 0,
|
||||
} = order;
|
||||
} = mergedJson;
|
||||
if (0 === rate) {
|
||||
for (let i = 0; i < count; ++i) {
|
||||
this.entity.emitParticleJson(mergedJson);
|
||||
|
|
Loading…
Reference in New Issue
Block a user