diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f3da43..6cc86a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ const query = new Query({}) ### Fixed +- Fixed issue where `ParticleEmitter` `Particle` did not receive z index value from emitter when in World space - Fixed issue where an animation that was `anim.reset()` inside of an animation event handler like `anim.once('end', () => anim.reset())` would not work correctly - Fixed issue where `GpuParticleEmitter` did not rotate with their parents - Fixed issue where Cpu `ParticleEmitter` did not respect `ParticleTransform.Local` diff --git a/src/engine/Particles/ParticleEmitter.ts b/src/engine/Particles/ParticleEmitter.ts index 425aada4..eb69d3c7 100644 --- a/src/engine/Particles/ParticleEmitter.ts +++ b/src/engine/Particles/ParticleEmitter.ts @@ -156,6 +156,7 @@ export class ParticleEmitter extends Actor { beginColor: this.particle.beginColor, endColor: this.particle.endColor, pos: vec(ranX, ranY), + z: this.particle.transform === ParticleTransform.Global ? this.z : undefined, vel: vec(dx, dy), acc: this.particle.acc, angularVelocity: this.particle.angularVelocity, diff --git a/src/engine/Particles/Particles.ts b/src/engine/Particles/Particles.ts index 6e19a5ff..222b9648 100644 --- a/src/engine/Particles/Particles.ts +++ b/src/engine/Particles/Particles.ts @@ -94,6 +94,7 @@ export class Particle extends Entity { this.transform.pos = options.pos ?? this.transform.pos; this.transform.rotation = options.rotation ?? 0; this.transform.scale = vec(1, 1); + this.transform.z = options.z ?? 0; this.motion.vel = options.vel ?? this.motion.vel; this.motion.angularVelocity = options.angularVelocity ?? 0; @@ -198,6 +199,10 @@ export interface ParticleConfig { * Starting rotation of the particle */ rotation?: number; + /** + * Optionally set the z index of the particle, default is 0 + */ + z?: number; /** * Size of the particle in pixels */ diff --git a/src/spec/vitest/ParticleSpec.ts b/src/spec/vitest/ParticleSpec.ts index 5147ca4a..dfbde073 100644 --- a/src/spec/vitest/ParticleSpec.ts +++ b/src/spec/vitest/ParticleSpec.ts @@ -279,6 +279,7 @@ describe('A particle', () => { randomRotation: false }, pos: new ex.Vector(0, 0), + z: 5, width: 20, height: 30, isEmitting: true, @@ -294,5 +295,10 @@ describe('A particle', () => { expect(emitter.children.length).toBe(0); expect(engine.currentScene.actors.length).toBe(1); expect(engine.currentScene.world.entityManager.entities.length).toBe(21); + expect( + engine.currentScene.world.entityManager.entities + .filter((entity) => entity instanceof ex.Particle) + .every((entity) => entity.transform.z === 5) + ).toBeTruthy(); }); });