Import a sprite sheet into Phaser
Phaser 3 loads a sheet with a frame size and builds animations from frame numbers.
What you need
- A sprite sheet PNG. Every SpriteForge download is a ZIP with the PNG, a JSON atlas and an import guide.
- The numbers from that import guide: frame size, columns and rows, frame count and frame rate.
The steps below use a typical sheet: 25 frames of 256 × 256 pixels in 6 columns and 5 rows. Frames run left to right, then top to bottom. Use the numbers from your own guide.
Steps
- Copy the PNG into your project's assets folder.
- Load it in
preload()with the frame size from your guide. - Create the animation in
create()from the first to the last frame, with the frame rate from your guide. - Add a sprite and play the animation.
preload() {
this.load.spritesheet('hero-walk', 'assets/walk.png', {
frameWidth: 256, frameHeight: 256, startFrame: 0, endFrame: 24
});
}
create() {
this.anims.create({
key: 'walk',
frames: this.anims.generateFrameNumbers('hero-walk', { start: 0, end: 24 }),
frameRate: 12, repeat: -1
});
this.add.sprite(100, 100, 'hero-walk').play('walk');
}
Good to know
- Give each sheet its own texture key and each animation its own key.
- For pixel art, set
pixelArt: truein the game config. - This is guidance for a regular grid sheet. Test it in your own project and engine version.
Official documentation: Phaser loader: spritesheet, Phaser animations.
No sprite sheet yet?
Upload one character image, pick a motion, and AI animates it. You get a sheet like the one above in about a minute, with three free animations every month.
Other engines
New to sprite sheets? Read the sprite sheet guide.