Jump to content

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


mauro98
 Share

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...

Hi,

I usually work with a mapping object.

Example:
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);
anim.animations.play();

Hope this helps.

BR
Marco Barroso

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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