Jump to content

Make Animation from separate files (ie not spritesheet)


AdamRyanGameDev
 Share

Recommended Posts

Good morining!

From the API I believe animation is preloaded like so....

this.load.spritesheet('dude', 
        'src/games/firstgame/assets/dude.png',
        { frameWidth: 32, frameHeight: 48 }
    );

and then animated like so

this.anims.create({
    key: 'left',
    frames: this.anims.generateFrameNumbers('dude', { start: 0, end: 3 }),
    frameRate: 10,
    repeat: -1
});

However I would like to sometimes work off a list of .pngs eg face1.png, face2.png rather than a sprite sheet, how would I go about this via the animationManager, or would I have to manage it myself with a looping system of mine within the gameloop?

Link to comment
Share on other sites

Sure you can :)

Here's a quick example I made:

http://labs.phaser.io/view.html?src=src\animation\animation from png sequence.js

and the code:

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

var game = new Phaser.Game(config);

function preload ()
{
    this.load.path = 'assets/animations/';

    this.load.image('cat1', 'cat1.png');
    this.load.image('cat2', 'cat2.png');
    this.load.image('cat3', 'cat3.png');
    this.load.image('cat4', 'cat4.png');
}

function create ()
{
    this.anims.create({
        key: 'snooze',
        frames: [
            { key: 'cat1', frame: null },
            { key: 'cat2', frame: null },
            { key: 'cat3', frame: null },
            { key: 'cat4', frame: null, duration: 50 }
        ],
        frameRate: 8,
        repeat: -1
    });

    this.add.sprite(400, 300, 'cat1').play('snooze');
}

 

Link to comment
Share on other sites

  • 1 month later...
 Share

  • Recently Browsing   0 members

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