# Spine animation for PixiJS

> Load an Animate4Me Spine 4.2 export in PixiJS with the official spine-pixi-v8 runtime: install, Assets.add, Spine.from and tested code to play idle and win.

Page: https://animate4me.com/spine-animation-for-pixijs.html

This guide shows how to play a Spine 4.2 animation made with Animate4Me in PixiJS with the official **spine-pixi-v8** runtime. It is the same runtime family our browser preview uses (spine-pixi-v8 4.2 on PixiJS 8).

We ran the code below with pixi.js 8.8.1 and spine-pixi-v8 4.2.88 on our [example export](https://animate4me.com/download/animate4me_ring_v2_spine42.zip) (0.5 MB).

[Try it](https://animate4me.com/app.html) [See pricing](https://animate4me.com/pricing.html)

## How do I use an Animate4Me animation in PixiJS?

Animate4Me gives you a Spine 4.2 export that spine-pixi-v8 loads with Assets and Spine.from, the same way our preview plays it.

**Best for:** Web game developers on PixiJS who need animated icons, items, props or characters.

**Key advantages:**

- What you see in the preview is what PixiJS plays: same runtime family.
- Standard Spine 4.2 JSON, atlas and one PNG page per symbol.
- Named animations such as `idle` and `win`.
- Straight-alpha pages read from the atlas header.

**What you get:** one ZIP with skeleton.json, skeleton.atlas, a PNG page and a README; 20 tokens per symbol or object from your image.

## Install the runtime

Pin the 4.2 line: the npm `latest` tag is already a newer Spine version, and the runtime major.minor version must match the export.

```
# PixiJS 8
npm install pixi.js@8 @esotericsoftware/spine-pixi-v8@~4.2.0

# PixiJS 7
npm install pixi.js@7 @esotericsoftware/spine-pixi-v7@~4.2.0
```

Recent 4.2 releases of spine-pixi-v8 list a recent PixiJS 8 as a peer dependency; if your project is on an older PixiJS 8, check the peer dependency and pin a matching 4.2 release.

## Put the files in your game

Unzip the export into a folder your game serves, for example `public/spine/ring/`, and keep the three files together.

- `skeleton.json`: Spine 4.2 skeleton data with bones, weighted meshes and one named animation per template you chose (for example `idle` and `win`).
- `skeleton.atlas`: the texture atlas description. Its header says `pma: false`: the pages are straight alpha, not premultiplied.
- `skeleton.png`: the atlas page. A symbol or object export is one page, usually about 450 to 1,500 px on each side, in a ZIP of about 0.1 to 1.8 MB.
- `README.txt`: the animation list and loading notes.

## Load and play it

```
import { Application, Assets } from "pixi.js";
import { Spine } from "@esotericsoftware/spine-pixi-v8";

const app = new Application();
await app.init({ resizeTo: window, backgroundAlpha: 0 });
document.body.appendChild(app.canvas);

Assets.add({ alias: "ringData", src: "/spine/ring/skeleton.json" });
Assets.add({ alias: "ringAtlas", src: "/spine/ring/skeleton.atlas" });
await Assets.load(["ringData", "ringAtlas"]);

const ring = Spine.from({ skeleton: "ringData", atlas: "ringAtlas", scale: 0.5 });
ring.position.set(app.screen.width / 2, app.screen.height / 2);
ring.state.setAnimation(0, "idle", true);
app.stage.addChild(ring);

// play win once, then go back to idle
ring.eventMode = "static";
ring.on("pointerdown", () => {
  ring.state.setAnimation(0, "win", false);
  ring.state.addAnimation(0, "idle", true, 0);
});
```

In spine-pixi-v8 4.2 a Spine object is created with the static `Spine.from()`. The atlas header says `pma: false`, and the loader reads it, so no alpha option is needed. The `scale` option scales the skeleton when it is read; the export is sized in pixels.

## Troubleshooting

- **Version or parse errors:** the installed spine-pixi is not 4.2. Reinstall with `@~4.2.0`.
- **404 for skeleton.png:** the PNG is not next to the atlas.
- **The animation does not move:** check the animation name against the README in the ZIP.

## How much does it cost?

A symbol or object animation from your image costs **20 tokens**, from a text prompt **30 tokens**; a character costs **60 tokens** from an image. Tokens come with a monthly plan: **Indie** $19 a month for 300 tokens, **Studio** $59 a month for 1200 tokens, **Pro** $199 a month for 5000 tokens. There is no free trial and there are no free tokens. Your first plan payment comes with a 7-day money-back, see the [Refund Policy](https://animate4me.com/refund.html); if an animation fails on our side, its tokens are returned automatically.

## Questions and answers

### Which spine-pixi package do I need?

@esotericsoftware/spine-pixi-v8 for PixiJS 8 or @esotericsoftware/spine-pixi-v7 for PixiJS 7, on the 4.2 line (@~4.2.0).

### Is it the same runtime as the Animate4Me preview?

Yes. The preview plays the animation with spine-pixi-v8 4.2 on PixiJS 8.

### Do I need to set premultiplied alpha?

No. The atlas header says pma: false and the loader reads it.

### Can I scale the animation?

Yes. Pass scale to Spine.from, or scale the Spine object like any other PixiJS container.

### Do I need a Spine licence?

The exported files are yours. To play them in your own product with an official Spine Runtime you need your own Spine licence from Esoteric Software, the same as for any Spine export.

## Related

- [Spine animation for Phaser](https://animate4me.com/spine-animation-for-phaser.html)
- [Spine animation on a web page](https://animate4me.com/spine-web-player-embed.html)
- [Spine export for game engines](https://animate4me.com/spine-export-for-game-engines.html)
- [Batch-animate game assets with the API](https://animate4me.com/batch-animate-game-assets-api.html)
- [Animate4Me home](https://animate4me.com/)

## Make a Spine animation for your PixiJS game.

[Try it](https://animate4me.com/app.html)

[Plans and token prices](https://animate4me.com/pricing.html)

---

Animate4Me: https://animate4me.com/ · Contact: contact@animate4me.com · X: https://x.com/Animate4Me · All pages for AI assistants: https://animate4me.com/llms.txt

Spine is a trademark of Esoteric Software. Animate4Me is not affiliated.
