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

Animation Event SPRITE_ANIMATION_COMPLETE fires immediately #4894

Closed
scott20145 opened this issue Dec 2, 2019 · 1 comment
Closed

Animation Event SPRITE_ANIMATION_COMPLETE fires immediately #4894

scott20145 opened this issue Dec 2, 2019 · 1 comment

Comments

@scott20145
Copy link

scott20145 commented Dec 2, 2019

Version

  • Phaser Version: 3.19.0
  • Operating system:
  • Browser:

Description

The sprite is playing a loop animation, and it will play a attack animation then back to loop animation. In this situation, event SPRITE_ANIMATION_COMPLETE will triggered immediately when attack triggered, so attack animation won't be displayed.

pseudo code:

// MySprite.ts
// play(key: 'string', loop?: boolean ):Promise;
const item = new MySprite();
item.play('loop', true);

window.setTimeout(() => {
    item.play('attack', false).then(() => {
        item.play('loop', true);
    });
},3000);

The reason is because when loading animation it will check if it is playing:

   //Phaser.GameObjects.Components.Animation
    load: function (key, startFrame)
    {
        if (startFrame === undefined) { startFrame = 0; }

        if (this.isPlaying)
        {
            this.stop();
        }
      //...
    },

It should be a different event like animation_stop but not animation_completed in my opinion. I think it is a bit unclear.

Current workaround is to set isPlaying = false before playing animation.

Or I missed anything?

Example Test Code

Additional Information

@photonstorm
Copy link
Collaborator

Thank you for submitting this feature request. We have implemented this and the feature 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants