Create Animation Without Frame Names
Demonstrates how to create a sprite animation by passing a texture atlas key directly to the animation configuration, allowing Phaser to automatically extract and numerically sort all frames within that atlas.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.atlas('zombie', 'assets/tests/zombie-no-pivot.png', 'assets/tests/zombie-no-pivot.json');
}
create ()
{
// Here we just pass the texture atlas key to `create` and it will extract all frames
// from within it, numerically sorting them for the animation.
this.anims.create({
key: 'walk',
frames: 'zombie',
frameRate: 12,
repeat: -1
});
this.add.sprite(400, 300).play('walk');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
pixelArt: true,
width: 800,
height: 600,
scene: Example
};
const game = new Phaser.Game(config);