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

sprite.anims.nextAnim change to undefined, will not recover from it #5852

Closed
Pythux opened this issue Oct 2, 2021 · 1 comment
Closed

sprite.anims.nextAnim change to undefined, will not recover from it #5852

Pythux opened this issue Oct 2, 2021 · 1 comment

Comments

@Pythux
Copy link

Pythux commented Oct 2, 2021

Version

  • Phaser Version: 3.55.2

Description

https://newdocs.phaser.io/docs/3.55.1/Phaser.GameObjects.Sprite#chain
https://newdocs.phaser.io/docs/3.55.2/Phaser.Animations.AnimationState#nextAnim

Chaining an animation set anims.nextAnim, if null, to the animation to chain, but after running sprite.play(...) the value turn to undefined, thus the animation to chain goes to anims.nextAnimsQueue leaving anims.nextAnim to undefined forever.

Example Test Code

console.log(sprite.anims.nextAnim) // null
sprite.chain(key)
console.log(sprite.anims.nextAnim) // given key
sprite.play(key)
console.log(sprite.anims.nextAnim) // undefined, it's a bug ?

full running code: (run on https://labs.phaser.io/edit.html)

class Example extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    preload ()
    {
        this.load.atlas('knight', 'assets/animations/knight.png', 'assets/animations/knight.json');
        this.load.image('bg', 'assets/skies/clouds.png');
    }

    create ()
    {
        //  The background and floor
        this.add.image(400, 16, 'bg').setOrigin(0.5, 0);

        var text = this.add.text(400, 8, 'Click to execute the bug (see logs)', { color: '#ffffff' }).setOrigin(0.5, 0);

        //  Our animations
        this.anims.create({
            key: 'guardStart',
            frames: this.anims.generateFrameNames('knight', { prefix: 'guard_start/frame', start: 0, end: 3, zeroPad: 4 }),
            frameRate: 8
        });

        this.anims.create({
            key: 'idle',
            frames: this.anims.generateFrameNames('knight', { prefix: 'idle/frame', start: 0, end: 5, zeroPad: 4 }),
            frameRate: 8,
            repeat: -1
        });

        var lancelot = this.add.sprite(500, 300)

        lancelot.setScale(8);
        lancelot.play('idle');

        // the bug to run here:
        this.input.on('pointerdown', function () {
            console.log(lancelot.anims.nextAnim) // null
            lancelot.chain('guardStart')
            console.log(lancelot.anims.nextAnim) // guardStart
            lancelot.play('idle')
            console.log(lancelot.anims.nextAnim) // undefined, it's a bug ?

        }, this)

    }
}

const config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    width: 800,
    height: 600,
    backgroundColor: '#026bc6',
    pixelArt: true,
    scene: [ Example ]
};

const game = new Phaser.Game(config);
@photonstorm
Copy link
Collaborator

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.

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