Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParticleEmitter ignores z-index #2972

Closed
ikiselev1989 opened this issue Mar 17, 2024 · 2 comments
Closed

ParticleEmitter ignores z-index #2972

ikiselev1989 opened this issue Mar 17, 2024 · 2 comments
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@ikiselev1989
Copy link

Hi! ParticleEmitter ignores z-index.
I use it with ParticleTransform.Local.
code here

import {
  Engine,
  EmitterType,
  ParticleEmitter,
  vec,
  Actor,
  Rectangle,
  Color,
  ParticleTransform,
} from 'excalibur';

class Game extends Engine {
  constructor(props) {
    super(props);
  }

  onInitialize() {
    this.currentScene.camera.pos.setTo(0, 0);

    this.addActor();
    this.addEmitter();
  }

  addActor() {
    const actor = new Actor({
      width: 200,
      height: 200,
      z: 1,
    });

    actor.graphics.use(
      new Rectangle({
        width: actor.width,
        height: actor.height,
        color: Color.Blue,
      })
    );

    this.currentScene.add(actor);
  }

  addEmitter() {
    const emitter = new ParticleEmitter({
      width: 400,
      height: 400,
      x: 0,
      y: -50,
      emitterType: EmitterType.Circle,
      radius: 250,
      acceleration: vec(0, -100),
      minVel: 0,
      maxVel: 0,
      minAngle: 0.6,
      maxAngle: 2.8,
      opacity: 1,
      emitRate: 100,
      fadeFlag: false,
      isEmitting: true,
      particleLife: 1500,
      maxSize: 1,
      minSize: 1,
      startSize: 40,
      endSize: 0,
      particleTransform: ParticleTransform.Local,
    });

    emitter.z = 2;

    this.currentScene.add(emitter);
  }
}

const engine = new Game({
  width: 600,
  height: 400,
});

engine.start();

`
@eonarheim
Copy link
Member

eonarheim commented Mar 17, 2024

@ikiselev1989 Definitely a bug! I have a commit on main that hasn't shipped yet (I'll be cutting a v0.29.2 very soon, otherwise the alpha has the fix)

Here is a potential workaround for now, it involves monkeypatching the particle emitter. You need to pick a z unfortunately so less ideal

const original = (ParticleEmitter.prototype as any)._createParticle;
(ParticleEmitter.prototype as any)._createParticle = function () {
  const particle = original.call(this);
  const tx = particle.get(TransformComponent);
  tx.z = 100;
  return particle;
}

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Mar 17, 2024
@eonarheim
Copy link
Member

Fixed in the latest release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

No branches or pull requests

2 participants