Jump to content

How can I create an animation from separate spritesheets/atlases in Phaser?


Recommended Posts

Say I have a sequence of 100 png images (523x482 each frame).

I'm thinking on creating groups of 9 images in a spritesheet or atlas.
But is it possible to create an animation from separate spritesheets/atlas?

    // frame00 and frame01 are spritesheets with 9 frames.
    const anim = this.game.add.sprite(265, 70, 'frame_00', 0, scene);
    anim.animations.add('anim', ['frame_01']); // it does not work
    anim.animations.play('anim', 30, true);

Got the following error:

    phaser.min.js:3 Uncaught TypeError: Cannot read property 'index' of undefined
    at i.Animation.updateCurrentFrame (phaser.min.js:3)
    at i.Animation.play (phaser.min.js:3)
    at i.AnimationManager.play (phaser.min.js:3)

How can I create an animation from this sequence or what would be the best approach to follow?

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 weeks later...


I usually work with a mapping object.

this.animations = {
        'up': [3, 2, 1, 0],
        'Down': [0, 1, 2, 3]        

let anim =  this.game.add.sprite(x, y, 'sprite');
anim.animations.add('up', this.animations.up);

Hope this helps.

Marco Barroso

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...