Make Animation from separate files (ie not spritesheet)

Recommended Posts

Good morining!

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

        { frameWidth: 32, frameHeight: 48 }

and then animated like so

    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?

Share this post

Link to post
Share on other sites

Sure you can :)

Here's a quick example I made:\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 ()
        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');


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.