phaser
phaser copied to clipboard
SetEmitterAngle does not work on Particle Emitter
Version
- Phaser Version: 3.70
- Operating system: Windows
- Browser: Firefox
Description
SetEmitterAngle has various incorrect effects/no effect on the emitter. The only one that seems to work correctly is if the angle was originally defined as a number and then setEmitterAngle is given a number. Any other combination seems to have unpredictable effects.
Example Test Code
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, 100, 'flares', {
frame: [ 'red', 'green', 'blue' ],
speed: 300,
angle:0,
// angle:[50, 80],
// angle: { min:50, max:80},
lifespan: 4000,
scale: 0.4,
blendMode: 'ADD'
});
this.input.on('pointerdown', pointer => {
// emitter.setEmitterAngle(50)
emitter.setEmitterAngle([150, 80])
// emitter.setEmitterAngle({min:50, max:80})
});
}
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#000',
parent: 'phaser-example',
scene: Example
};
const game = new Phaser.Game(config);
Additional Information
This code is edited from the example: https://labs.phaser.io/edit.html?src=src/game%20objects\particle%20emitter\multiple%20death%20zones.js
The only one that seems to work correctly is if the angle was originally defined as a number and then setEmitterAngle is given a number.
I think this is true of all the EmitterOps since v3.60. A workaround is
emitter.ops.angle.loadConfig({ angle: { min: 50, max: 80 } });
This is correct, it's not possible to change the EmitterOp type post-creation without reloading the config. If you start it with a number, you can change it to another number, but not an array, for example. If you need to dynamically change it, use a callback op type in the initial config.