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

PathParticle throws "TypeError: this.next is null" when speed has no interpolation #129

Closed
MxAshUp opened this issue Apr 29, 2020 · 2 comments

Comments

@MxAshUp
Copy link
Contributor

MxAshUp commented Apr 29, 2020

Background
It took me a while to get the ParticlePath working, but following the example code I finally got it, with one exception: when I had the speed set to no interpolation (ie start speed = end speed) I got an error "TypeError: this.next is null".

How to reproduce

  var emitter = new Emitter(
    container,
    [sprite],
    {
      ...
      "speed": {
        "start": 100,
        "end": 100,
        "minimumSpeedMultiplier": 1
      },
      "extraData": {
        "path":"sin(x/10)*20"
      },
    });

    emitter.particleConstructor = PathParticle;

Solution
I've debugged the code enough to understand the cause. In PathParticle here: https://github.com/pixijs/pixi-particles/blob/master/src/PathParticle.ts#L153, the code assumes speedList needs to be interpolated. I think the solution involves first checking if this._doSpeed is true. If I understand PathParticle correctly the fix should look something like this:

if(this._doSpeed) {
  const speed = this.speedList.interpolate(lerp) * this.speedMultiplier;
  this.movement += speed * delta;
} else {
  const speed = ParticleUtils.length(this.velocity);
  this.movement += speed * delta;
}

EDIT: Workaround
For anyone seeing this issue and needing a workaround (providing this isn't closed yet), I recommend setting speed start and end to nearly the same value, for example:

      "speed": {
        "start": 100,
        "end": 100.0001,
        "minimumSpeedMultiplier": 1
      },

I'll get a PR started

MxAshUp added a commit to MxAshUp/pixi-particles that referenced this issue Apr 29, 2020
MxAshUp added a commit to MxAshUp/pixi-particles that referenced this issue Apr 29, 2020
MxAshUp added a commit to MxAshUp/pixi-particles that referenced this issue Apr 29, 2020
@MxAshUp
Copy link
Contributor Author

MxAshUp commented Apr 29, 2020

I also noticed that PathParticle ignores acceleration. But this may be expected behavior. However adding acceleration support for PathParticle could be easy (this is tested and works):

// PathParticle.update()
// ...
if(this._doSpeed) {
    const speed = this.speedList.interpolate(lerp) * this.speedMultiplier;
    this.movement += speed * delta;
} else {
    // Adapted from Particle.update()
    if (this._doAcceleration) {
        this.velocity.x += this.acceleration.x * delta;
        this.velocity.y += this.acceleration.y * delta;
        if (this.maxSpeed) {
            var currentSpeed = ParticleUtils.length(this.velocity);
            if (currentSpeed > this.maxSpeed) {
                ParticleUtils.scaleBy(this.velocity, this.maxSpeed / currentSpeed);
            }
        }
    }

    const speed = ParticleUtils.length(this.velocity);
    this.movement += speed * delta;
}
// ...

Maybe open a feature request for it?

@andrewstart
Copy link
Collaborator

andrewstart commented Apr 30, 2020

Ignoring acceleration is intentional - PathParticles are supposed to move in an exact path, and being affected by gravity/wind would interfere with that. Merely changing this.movement would be different behavior than what acceleration does to normal particles, and basically duplicates what interpolating speed values does.

andrewstart pushed a commit that referenced this issue Apr 30, 2020
* Fix issue #129 - PathParticle throws error when no speed interp

* use this.speedList.current.value instead of length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants