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.11k stars 7.1k forks source link

Particles - startFollow causes x/y step particle emitters to not emit in steps (all emit from single coordinate) #5847

Closed sreadixl closed 1 year ago

sreadixl commented 3 years ago

Version

Description

If you create a particle emitter with x/y values that are EmitterOpSteppedConfig (start/end/steps) objects, then have the Particle Emitter follow another object using startFollow, instead of the particles emitting in steps, all the particles will emit from a single point.

Example Test Code

The following code will replicate the issue:

let follow = this.add.rectangle(0, 100, 400, 20, 0xff0000);
this.add.tween({targets:follow, duration: 10000, props:{x: this.scale.width}, yoyo:true, repeat:-1})
var stepConfig = {
    x: {start:0, end:this.scale.width, steps:6},
    y: 100,
    speedY: 100,
    speedX: Math.cos(120*Math.PI/180)*100,
    lifespan:4000,
    radial:true,
    rotate: 120,
    scale:1,
    quantity: 6,
    frequency:1000,
}
this.add.particles("myparticle").createEmitter(stepConfig).startFollow(follow);

If you comment out the stepFollow you will see how the particles should appear. Changing the size of the follow object and the size of the x start/end doesn't fix the issue - I originally thought if the width of the follow object was greater than the distance between start and end, it would fix the issue, but it doesn't.

Additional Information

I ran into this issue because I was updating an old game that was using 3.20.0 (beta I think) to 3.55.2 and a particle effect that was suppose to create rain wasn't working right. It's possible that the way it worked in 3.20.0 was actually wrong and that the behavior in 3.55.2 is actually the expected behavior. It's also possible that there is a config setting I'm missing that would fix the issue as well, but I haven't been able to find what that config option is, if one does exist.

samme commented 3 years ago

Compare v3.24.1 vs v3.55.2.

sreadixl commented 3 years ago

Compare v3.24.1 vs v3.55.2.

That doesn't show the issue I was referring to - though the emit point seems to be different - but you can see the issue I was referring to by changing the x property in the emit config to {start:-120, end:120, steps:6}. In 3.24.1 the particles emit along the top of the image in a line, while in 3.55.2 they emit from a single point.

photonstorm commented 1 year ago

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Test here: https://labs.phaser.io/view.html?src=src/bugs/5847%20step%20particles.js&v=dev