Skip to content

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

Closed
@Pythux

Description

@Pythux

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions