Skip to content

[3.50] "delay" property in animation config results in uninterruptible/unstable animation #5680

@enderandpeter

Description

@enderandpeter

Version

  • Phaser Version: 3.54.0 (earliest version with issue: 3.50.0-beta.7)
  • Operating system: Any, but using Windows 10 right now
  • Browser: Firefox Any, but using Firefox right now

Description

When the delay property is set on an animation configuration, the animation is put in an unstable state where it is either not acknowledged or unable to be interrupted.

Expected

When setting the delay property on an animation config, the animation will be delayed the set number of milliseconds before starting. Also, when another animation is played, it will interrupt the animation currently being played.

Actual

When the delay property is set, the animation fails to load its initial frame when the game loads, and the animation cannot be interrupted by another.

Example Test Code

I was trying to explain this in the Discord forum, but I felt like no one knew what the heck I was talking about. And so plenty more details are here.

The problem can be seen in this GitLab project. It is a codebase that is gradually getting more sophisticated, but the general problem is exhibited.

The animations, such as the idle_left animation, generally look like this

import {Animations, Types} from 'phaser';

export default class Left extends Animations.Animation {
    static key = 'idle_left';
    constructor(manager: Animations.AnimationManager) {
        const { key } = Left;
        const config: Types.Animations.Animation = {
            key,
            frames: manager.generateFrameNames('atlas', {
                prefix: `player/mp_${key}_`,
                suffix: '.png',
                start: 1,
                end: 2,
                zeroPad: 2
            }),
            frameRate: 10,
            repeat: -1,
            repeatDelay: 5000,
            delay: 3000,
            yoyo: true
        };
        super(manager, key, config);
    }
}

Please try deploying this project to see what I am talking about. Instructions are in the readme. Basically, clone the repo, install with yarn or npm, copy the example config file to a real config file, and run yarn start or npm start in the app folder. This project was scaffolded with Create React App and it uses TypeScript.

I tried to keep things generally organized. The runnable app is in the app folder. Assets the project needs, like spritesheets and meta data, are in app/public/assets. Everything is organized in classes. Sprites are in app/src/Sprites, scenes are in app/src/Scenes, and animations are in app/src/animations. Of particular note are the Player animations.

Please let me know if you have any questions.

Additional Information

When the Idle and Walk animations work properly, the character moves like this:

Proper-Animation-Delay

Note how when the page initially loads, the frame that loads is the first frame in the idle_right animation. Also, there is a few seconds of delay before the character blinks (the Idle animation). Note how after making the character move in either direction and stopping, again there is a few seconds of delay before the Idle animation, and the character is facing in that direction. This is how this is supposed to work.

When using at least Phaser 3.50.0-beta.7, this happens:

Broken.Animation.Delay.mp4

The video file size is much smaller as an MP4 than an animated GIF.

Note how the Character sprite starts with the first sprite listed in app/public/assets/atlas.json instead of the first sprite of the idle_right animation. After a few seconds, you will see that it does start playing the idle animation properly. But when you move the character, it is frozen in a frame, I'm not sure exactly which one, I think the first or last one played in the idle animation. Then you will see how at one point, the walking animation suddenly plays, but I am not even pressing anything. This behavior is actually a fluke that only occurred when I used a new screen recording program. The typical behavior is that when I move the character to the left, they remain facing to the right and the walking animation does not play. After a few seconds, the idle_left animation plays but the delay seems a little longer. Anyway, as you can see, things are clearly not working.

However, if the delay property is removed from the Idle animations, you will see this:

Improper.Animation.Delay.mp4

Everything is pretty much normal now, but only because the delay for the idle animation has been commented out. You will see how this restored the first frame in the idle animation to load this time at the start of the scene. But since the delay property is removed, the character starts blinking immediately instead of the delay.

Can anyone help determine why this is happening? Why does the delay property on an animation config cause this broken behavior in newer Phaser?

Again, the earliest version on which I could confirm this issue occurs was 3.50.0-beta.7. The latest version that did not have this issue was 3.50.0-beta.2. I could not get 3.50.0-beta.4 to load. It gave me the dreadful "Phaser could not be found" error.

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