refactor: optional particle scaling
This commit is contained in:
parent
ab812ec985
commit
1c15d81df3
|
@ -21,10 +21,6 @@ export default () => class Emitted extends decorate(Trait) {
|
|||
|
||||
#rotationAdd;
|
||||
|
||||
#scaleStart;
|
||||
|
||||
#scaleEnd;
|
||||
|
||||
#ttl;
|
||||
|
||||
#velocityAngle;
|
||||
|
@ -41,8 +37,6 @@ export default () => class Emitted extends decorate(Trait) {
|
|||
this.#position = null;
|
||||
this.#rotationStart = new Range(params.rotation.start);
|
||||
this.#rotationAdd = new Range(params.rotation.add);
|
||||
this.#scaleStart = new Range(params.scale.start);
|
||||
this.#scaleEnd = new Range(params.scale.end);
|
||||
this.#ttl = new Range(params.ttl);
|
||||
this.#velocityAngle = new Range(params.velocity.angle);
|
||||
this.#velocityMagnitude = new Range(params.velocity.magnitude);
|
||||
|
@ -147,8 +141,6 @@ export default () => class Emitted extends decorate(Trait) {
|
|||
}
|
||||
this.#rotationStart = new Range(this.params.rotation.start);
|
||||
this.#rotationAdd = new Range(this.params.rotation.add);
|
||||
this.#scaleStart = new Range(this.params.scale.start);
|
||||
this.#scaleEnd = new Range(this.params.scale.end);
|
||||
this.#ttl = new Range(this.params.ttl);
|
||||
this.#velocityAngle = new Range(this.params.velocity.angle);
|
||||
this.#velocityMagnitude = new Range(this.params.velocity.magnitude);
|
||||
|
@ -160,7 +152,7 @@ export default () => class Emitted extends decorate(Trait) {
|
|||
particle: () => {
|
||||
const position = null === this.#position ? null : this.#position.value();
|
||||
const force = this.#force.value();
|
||||
return {
|
||||
const particle = {
|
||||
alpha: {
|
||||
start: this.#alphaStart.value(),
|
||||
end: this.#alphaEnd.value(),
|
||||
|
@ -173,16 +165,21 @@ export default () => class Emitted extends decorate(Trait) {
|
|||
start: this.#rotationStart.value(),
|
||||
add: this.#rotationAdd.value(),
|
||||
},
|
||||
scale: {
|
||||
start: this.#scaleStart.value(),
|
||||
end: this.#scaleEnd.value(),
|
||||
},
|
||||
ttl: this.#ttl.value(),
|
||||
velocity: {
|
||||
angle: this.#velocityAngle.value(),
|
||||
magnitude: this.#velocityMagnitude.value(),
|
||||
},
|
||||
};
|
||||
if (this.params.scale) {
|
||||
const scaleStart = new Range(this.params.scale.start);
|
||||
const scaleEnd = new Range(this.params.scale.end);
|
||||
particle.scale = {
|
||||
start: scaleStart.value(),
|
||||
end: scaleEnd.value(),
|
||||
};
|
||||
}
|
||||
return particle;
|
||||
},
|
||||
|
||||
};
|
||||
|
|
|
@ -196,17 +196,23 @@ export default (latus) => class Emitter extends decorate(Trait) {
|
|||
particle.rotation.add,
|
||||
'add',
|
||||
),
|
||||
new Proton.Scale(
|
||||
particle.scale.start,
|
||||
particle.scale.end,
|
||||
),
|
||||
];
|
||||
if (particle.scale) {
|
||||
behaviors.push(
|
||||
new Proton.Scale(
|
||||
particle.scale.start,
|
||||
particle.scale.end,
|
||||
),
|
||||
);
|
||||
}
|
||||
const protonParticle = this.#emitter.createParticle(
|
||||
initializers,
|
||||
behaviors,
|
||||
);
|
||||
protonParticle.particle = particle;
|
||||
entity.on('destroyed', () => {
|
||||
protonParticle.dead = true;
|
||||
delete protonParticle.particle;
|
||||
protonParticle.removeAllBehaviours();
|
||||
});
|
||||
if (particle.listed && this.entity.list) {
|
||||
|
@ -309,7 +315,9 @@ export default (latus) => class Emitter extends decorate(Trait) {
|
|||
particle.body.setPosition([particle.p.x, particle.p.y]);
|
||||
/* eslint-disable no-param-reassign */
|
||||
particle.body.opacity = particle.alpha;
|
||||
particle.body.visibleScale = [particle.scale, particle.scale];
|
||||
if (particle.particle.scale) {
|
||||
particle.body.visibleScale = [particle.scale, particle.scale];
|
||||
}
|
||||
particle.body.rotation = particle.rotation * PI_180;
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user