Loading your sprite sheet in Phaser and PixiJS

The tool exports a sprite sheet image plus a .json atlas in TexturePacker's "JSON Hash" format, a de facto standard. Here's how to play it in the two most popular JavaScript engines.

What's in the JSON

The atlas lists every frame by name with its x, y, w and h on the sheet. If you used Trim transparent padding, it also includes spriteSourceSize and sourceSize, so the engine can put the trimmed art back at its original position. A meta block records the image file name and sheet size.

Keep the image and JSON in the same folder and don't rename the image without updating meta.image.

Phaser 3

class Game extends Phaser.Scene {
  preload() {
    // atlas(key, imageURL, jsonURL)
    this.load.atlas('hero', 'assets/spritesheet.webp', 'assets/spritesheet.json');
  }
  create() {
    this.anims.create({
      key: 'hero-run',
      frames: this.anims.generateFrameNames('hero'), // every frame, in order
      frameRate: 12,
      repeat: -1                                     // loop forever
    });
    this.add.sprite(400, 300, 'hero').play('hero-run');
  }
}

Set frameRate to the capture FPS you used. For a ping-pong loop without baked frames, add yoyo: true.

PixiJS (v7 and v8)

import { Assets, AnimatedSprite } from 'pixi.js';

const sheet = await Assets.load('assets/spritesheet.json'); // loads the image too
const frames = Object.values(sheet.textures);
const hero = new AnimatedSprite(frames);
hero.animationSpeed = 12 / 60; // capture FPS / display FPS
hero.loop = true;
hero.play();
app.stage.addChild(hero);

Other engines

Troubleshooting

Create your sheet →