# Random animation delays?

**URL:** https://phaser.discourse.group/t/random-animation-delays/7353
**Category:** Phaser 3
**Created:** [September 4, 2020, 8:55am UTC](https://phaser.discourse.group/t/random-animation-delays/7353 "2020-09-04T08:55:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kittykatattack](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/kittykatattack/32/3888_2.png) [@kittykatattack](https://phaser.discourse.group/u/kittykatattack)
#### Post date: [September 4, 2020, 8:55am UTC](https://phaser.discourse.group/t/random-animation-delays/7353/1 "2020-09-04T08:55:08Z")

</div>

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`:

```javascript
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!! 🙂

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [September 4, 2020, 3:12pm UTC](https://phaser.discourse.group/t/random-animation-delays/7353/2 "2020-09-04T15:12:17Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![kittykatattack](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/kittykatattack/32/3888_2.png) [@kittykatattack](https://phaser.discourse.group/u/kittykatattack)
#### Post date: [September 7, 2020, 9:25am UTC](https://phaser.discourse.group/t/random-animation-delays/7353/3 "2020-09-07T09:25:14Z")

</div>

Thanks @samme!

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

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [September 9, 2020, 1:41am UTC](https://phaser.discourse.group/t/random-animation-delays/7353/4 "2020-09-09T01:41:38Z")

</div>

It is the [SPRITE\_ANIMATION\_KEY\_REPEAT](https://photonstorm.github.io/phaser3-docs/Phaser.Animations.Events.html#event:SPRITE_ANIMATION_KEY_REPEAT) event.

---

<div class="post-metadata">

### Author: ![kittykatattack](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/kittykatattack/32/3888_2.png) [@kittykatattack](https://phaser.discourse.group/u/kittykatattack)
#### Post date: [September 9, 2020, 12:52pm UTC](https://phaser.discourse.group/t/random-animation-delays/7353/5 "2020-09-09T12:52:19Z")

</div>

@samme Ah, thank you!

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