Pixi.js: `AnimatedSprite`: `onComplete` never fires

Created on 31 May 2017  路  8Comments  路  Source: pixijs/pixi.js

I have a three-frame animation stored in frames. I'd expect that this code would fire whenever the third frame is reached:

const jack = new PIXI.extras.AnimatedSprite(frames);
jack.onComplete = () => {
    console.log("complete");
};
jack.play();

However, it doesn't look like it's ever fired. onFrameChange, on the other hand, seems to work as expected, so I'm sure that I'm using onComplete the right way.

Is this a bug or am I doing something wrong?

Most helpful comment

It makes sense for onComplete not to fire if the animation is looped. A new onLoop callback would be a welcome PR imo. You can't rely on onFrameChange for a specific frame index in case the frame rate is low and you never actually hit that specific frame index

All 8 comments

Looking at the source code, it seems like onComplete isn't fired for loops. This might be unexpected behavior for some. A current workaround is to check if the current frame is the last frame in onFrameChange.

It makes sense for onComplete not to fire if the animation is looped. A new onLoop callback would be a welcome PR imo. You can't rely on onFrameChange for a specific frame index in case the frame rate is low and you never actually hit that specific frame index

I agree with @themoonrat, adding a new event that represents looping is the backwards compatible way to do this change.

Anyone fancy putting together a PR to add onLoop to AnimatedSprite?

I can do that tomorrow

PR merged to dev. The next release will have an onLoop callback.

Thank you! 馃帀

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

madroneropaulo picture madroneropaulo  路  3Comments

readygosports picture readygosports  路  3Comments

samueller picture samueller  路  3Comments

lucap86 picture lucap86  路  3Comments

courtneyvigo picture courtneyvigo  路  3Comments