Load Sprite Sheet From Object
This example shows how to load a sprite sheet by passing a single configuration object to the loader, specifying the asset key, URL, and frame dimensions.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.spritesheet({
key: 'explosion',
url: 'assets/sprites/explosion.png',
frameConfig: { frameWidth: 64, frameHeight: 64, endFrame: 23 }
});
}
create ()
{
const config = {
key: 'explodeAnimation',
frames: this.anims.generateFrameNumbers('explosion', { start: 0, end: 23, first: 23 }),
frameRate: 20,
repeat: -1
};
this.anims.create(config);
this.add.sprite(400, 300, 'explosion').play('explodeAnimation');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);