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

Particle DeathZones don't work #7006

Open
Stever1388 opened this issue Jan 9, 2025 · 1 comment
Open

Particle DeathZones don't work #7006

Stever1388 opened this issue Jan 9, 2025 · 1 comment

Comments

@Stever1388
Copy link

Stever1388 commented Jan 9, 2025

Version

  • Phaser Version: Phaser 3.86.0
  • Operating system: Windows
  • Browser: Chrome

Description

Adding a death zone to a particle emitter doesn't cause the particles to die if they enter the death zone (for onEnter death zones) or if they leave an onLeave death zone.

Example Test Code

This example shows it not working: https://phaser.io/examples/v3.85.0/game-objects/particle-emitter/view/multiple-death-zones

Also this example for onLeave death zones (which cause the particles to not work at all from what I can tell):

export default class ParticleDeathZoneIssue extends Phaser.Scene {
  preload() {
    this.load.atlas('flares', 'assets/images/flares.png', 'assets/images/flares.json');
  }

  create() {
    const rect = new Phaser.Geom.Rectangle(this.scale.width / 2 - 200, this.scale.height / 2 - 200, 400, 400);

    const emitter = this.add.particles(this.scale.width / 2, this.scale.height / 2, 'flares', {
      frame: ['red', 'green', 'blue'],
      speed: 300,
      gravityY: 400,
      lifespan: 4000,
      scale: 0.4,
      blendMode: 'ADD',
      deathZone: {
        type: 'onLeave',
        source: rect
      }
    });

    const graphics = this.add.graphics();
    graphics.lineStyle(1, 0x00ff00, 1);
    graphics.strokeRectShape(rect);
  }
}

Additional Information

If you set the particle emitter to follow an object, the death zones "sort of" work again.

export default class ParticleDeathZoneIssue extends Phaser.Scene {
  preload() {
    this.load.atlas('flares', 'assets/images/flares.png', 'assets/images/flares.json');
  }

  create() {
    this.followObj = this.add.circle(0,0,10,0xff0000);
    const rect = new Phaser.Geom.Rectangle(this.scale.width / 2 - 200, this.scale.height / 2 - 200, 400, 400);

    const emitter = this.add.particles(0,0, 'flares', {
      frame: ['red', 'green', 'blue'],
      speed: 300,
      gravityY: 400,
      lifespan: 4000,
      scale: 0.4,
      blendMode: 'ADD',
      deathZone: {
        type: 'onLeave', // change to 'onEnter' to test death on enter
        source: rect
      }
    });

    const graphics = this.add.graphics();
    graphics.lineStyle(1, 0x00ff00, 1);
    graphics.strokeRectShape(rect);

    emitter.startFollow(this.followObj);
  }

  update() {
    this.followObj.setPosition(this.input.activePointer.x, this.input.activePointer.y);
  }
}

The particles will correctly die if they enter the onEnter death zone or leave the onLeave death zone, but moving the mouse in and out of the rect will sometimes cause the particle system to stop spawning completely and/or cause particles to seemingly spawn from other positions (either inside or outside of the rect).

If you switch to v3.80.1 in this example, the death zones work correctly.

@photonstorm
Copy link
Collaborator

They do, but it's probably related to #6371 re: local/global coordinate changes. Likely, we should change it back (and it hasn't been fully done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants