phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.12k stars 7.1k forks source link

ParticleEmitter `speedX` and `speedY` Not Updating After Initial Creation #6877

Open monteiz opened 3 months ago

monteiz commented 3 months ago

Version

After creating a ParticleEmitter, subsequent changes to the emitter's speedX and speedY properties are not taken into account. Below is a minimal example demonstrating this issue. When the emitter is triggered on a pointer down event, the speed is supposed to be set to zero, but the particles still maintain their initial speed.

Example Test Code

To be pasted in this example:

class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.atlas('flares', 'assets/particles/flares.png', 'assets/particles/flares.json');
    }

    create ()
    {
        const emitter = this.add.particles(400, 250, 'flares', {
            frame: [ 'red', 'yellow', 'green' ],
            lifespan: 4000,
            speed: { min: 150, max: 250 },
            scale: { start: 0.8, end: 0 },
            gravityY: 150,
            blendMode: 'ADD',
            emitting: false
        });

        this.input.on('pointerdown', pointer => {

            emitter.explode(16);

            // Attempt to change particle speed to zero
            emitter.speedX = 0;
            emitter.speedY = 0;
            emitter.setParticleSpeed(0,0);

        });

        this.add.text(10, 10, 'Click to explode emit particles');
    }
}

const config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#000',
    parent: 'phaser-example',
    scene: Example
};

const game = new Phaser.Game(config);

Expected Behavior:

When the emitter is triggered by the pointer down event, the particle speed should be updated to the new values set (speedX and speedY to 0), resulting in particles emitting with no horizontal or vertical speed.

Actual Behavior:

Despite setting speedX and speedY to 0, the particles still emit with their initial speed values.

photonstorm commented 2 months ago

In the example you emit the particles and then set the emitter speed to zero. Speed is an onEmit property, not an onUpdate one, so the particles already launched will not be modified by changing the speed.