# What's the purpose of anims.chain?

**URL:** <https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809>\
**Category:** Phaser 3\
**Created:** [June 29, 2020, 11:40pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809 "2020-06-29T23:40:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![3b33](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/3b33/32/3334_2.png) [@3b33](https://phaser.discourse.group/u/3b33)\
**Post date:** [June 29, 2020, 11:40pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/1 "2020-06-29T23:40:19Z")

</div>

The command seems to skip the ‘run’ command.

`sprite.anims.play('run').anims.chain('walk');`

I’m trying to do three different animations one followed by the other from a single sprite sheet. The above code is `inside sprite.once('animationcomplete', ()=>{ });` so I can’t use animationcomplete again because ‘sprite’ already completed the first time. I tried creating a new sprite with a unique name (like sprite2) but it just makes things messy and confusing.

---

<div class="post-metadata">

**Author:** ![3b33](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/3b33/32/3334_2.png) [@3b33](https://phaser.discourse.group/u/3b33)\
**Post date:** [June 29, 2020, 11:43pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/2 "2020-06-29T23:43:41Z")

</div>

Never-mind. I think I figured it out. The first animation’s repeat is on…

---

<div class="post-metadata">

**Author:** ![3b33](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/3b33/32/3334_2.png) [@3b33](https://phaser.discourse.group/u/3b33)\
**Post date:** [June 29, 2020, 11:58pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/3 "2020-06-29T23:58:17Z")

</div>

After double checking, all my animations are set to 0 repeat. I still don’t know how this works.

---

<div class="post-metadata">

**Author:** ![3b33](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/3b33/32/3334_2.png) [@3b33](https://phaser.discourse.group/u/3b33)\
**Post date:** [June 30, 2020, 12:38am UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/4 "2020-06-30T00:38:16Z")

</div>

Doesn’t seem to work if there is more than one chain? [Paste here](https://labs.phaser.io/edit.html?)

```
var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    pixelArt: true,
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.atlas('gems', 'assets/tests/columns/gems.png', 'assets/tests/columns/gems.json');
}

function create ()
{
    this.anims.create({ key: 'diamond', frames: this.anims.generateFrameNames('gems', { prefix: 'diamond_', end: 15, zeroPad: 4 }), repeat: 0 });
    this.anims.create({ key: 'ruby', frames: this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 }), repeat: 2 });
    this.anims.create({ key: 'prism', frames: this.anims.generateFrameNames('gems', { prefix: 'prism_', end: 6, zeroPad: 4 }), repeat: 0 });

    var gem = this.add.sprite(400, 300, 'gems').setScale(4);

    // Play the diamond animation (which repeats 4 times)
    gem.play('diamond');

    // When it completes, play the ruby animation
    gem.anims.chain('prism');
    gem.anims.chain('ruby');
}
```

---

<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:** [June 30, 2020, 10:20pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/5 "2020-06-30T22:20:56Z")

</div>

You can’t chain more than one. Only the last one counts.

---

<div class="post-metadata">

**Author:** ![3b33](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/3b33/32/3334_2.png) [@3b33](https://phaser.discourse.group/u/3b33)\
**Post date:** [July 1, 2020, 3:49pm UTC](https://phaser.discourse.group/t/whats-the-purpose-of-anims-chain/6809/6 "2020-07-01T15:49:02Z")

</div>

Thanks. I found out how to use a custom sequence of frames instead. I knew there had to be a way to do that. [https://phaser.io/examples/v3/view/animation/generate-frames](https://phaser.io/examples/v3/view/animation/generate-frames)
