Random animation delays?

Hi Everyone,

I’m trying to create a looping animation with a random repeatDelay. This code should work but for some reason the new random value for repeatDelay isn’t being applied to the currentAnim:

const blinkAnimation = this.anims.create({
      key: "blink",
      frames: blinkFrames,
      frameRate: 10,
      repeat: -1,
      repeatDelay: 1000,
    });

    blinkAnimation.on("repeat", currentAnim => {
      currentAnim.repeatDelay = Phaser.Math.RND.integerInRange(2000, 6000);
    });

When I log the value of currentAnim.repeatDelay I can see the new random number is being applied, but the actual animation still just repeats based on the original value.

Any ideas what I might be doing wrong?

Thanks!! :slight_smile:

I think if the sprite is already playing then it won’t reload the modified animation.

You may want to work on the sprite instead:

sprite.on('animationrepeat-blink', function (anim, frame, repeatCount, gameObject) {
    gameObject.setRepeatDelay(Phaser.Math.RND.integerInRange(2000, 6000));
});

Thanks @samme!

In your example, where does the animationrepeat-blink event come from?

It is the SPRITE_ANIMATION_KEY_REPEAT event.

@samme Ah, thank you!

I’ve also realised that 3.5 might solve this a little more neatly… I’ll test and report back :slight_smile: