# Spine animation for Phaser

> Play an Animate4Me Spine 4.2 export in Phaser with the official spine-phaser runtime: npm packages, plugin setup and tested code to load and play idle and win.

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

This guide shows how to load a Spine 4.2 animation made with Animate4Me in a Phaser game with the official **spine-phaser** runtime from Esoteric Software.

We ran the code below with Phaser 3.90.0 and spine-phaser-v3 4.2.120 on our [example export](https://animate4me.com/download/animate4me_ring_v2_spine42.zip) (0.5 MB). The same calls work with spine-phaser-v4 for Phaser 4.

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

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

Animate4Me gives you a Spine 4.2 export that the official spine-phaser runtime loads with spineJson and spineAtlas.

**Best for:** Phaser developers who need animated game icons, items, props or characters for a web game.

**Key advantages:**

- Standard Spine 4.2 JSON, atlas and PNG for the official plugin.
- Named animations such as `idle` and `win`.
- Straight-alpha atlas marked `pma: false`, read automatically.
- Small files: a symbol export is one page and a ZIP of about 0.1 to 1.8 MB.

**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

The npm `latest` tag of the spine-phaser packages is already a newer Spine version, so pin the 4.2 line to match the export:

```
# Phaser 3 (3.60 or newer)
npm install phaser@3 @esotericsoftware/spine-phaser-v3@~4.2.0

# Phaser 4
npm install phaser@4 @esotericsoftware/spine-phaser-v4@~4.2.0
```

Our exports use weighted meshes, which spine-phaser draws only with the WebGL renderer. Use `type: Phaser.WEBGL` (or `Phaser.AUTO` on devices with WebGL).

## Put the files in your game

Unzip the export into a folder your game serves, for example `public/assets/ring/`. Keep the three files together: the atlas loads its PNG page from the same folder.

- `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 Phaser from "phaser";
import { SpinePlugin } from "@esotericsoftware/spine-phaser-v3";

function preload() {
  this.load.spineJson("ring-data", "assets/ring/skeleton.json");
  this.load.spineAtlas("ring-atlas", "assets/ring/skeleton.atlas");
}

function create() {
  const ring = this.add.spine(400, 300, "ring-data", "ring-atlas");
  ring.setScale(0.5);
  ring.animationState.setAnimation(0, "idle", true);

  // play win once, then go back to idle
  this.input.on("pointerdown", () => {
    ring.animationState.setAnimation(0, "win", false);
    ring.animationState.addAnimation(0, "idle", true, 0);
  });
}

new Phaser.Game({
  type: Phaser.WEBGL,
  width: 800,
  height: 600,
  plugins: {
    scene: [{ key: "spine.SpinePlugin", plugin: SpinePlugin, mapping: "spine" }],
  },
  scene: { preload, create },
});
```

`spineAtlas` reads `pma: false` from our atlas header, so you do not need to pass an alpha setting. For Phaser 4, import from `@esotericsoftware/spine-phaser-v4` instead. Without a bundler, the packages also ship script-tag builds that expose the same plugin as `spine.SpinePlugin`.

## Troubleshooting

- **Nothing appears, or a renderer error:** the game runs on the Canvas renderer. Use WebGL.
- **Version or parse errors:** the installed spine-phaser is not 4.2. Reinstall with `@~4.2.0`.
- **404 for skeleton.png:** the PNG is not next to the atlas file.

## 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-phaser package do I need?

@esotericsoftware/spine-phaser-v3 for Phaser 3.60 or newer, or @esotericsoftware/spine-phaser-v4 for Phaser 4, both on the 4.2 line (@~4.2.0) to match the Spine 4.2 export.

### Does it work with the Canvas renderer?

The exports use weighted meshes, which spine-phaser draws only with WebGL. Use the WebGL renderer.

### Do I need to set premultiplied alpha?

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

### Can I use the old Phaser 3 Spine plugin?

Use the official spine-phaser runtime from Esoteric Software instead; it loads Spine 4.2 data with spineJson and spineAtlas.

### 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 PixiJS](https://animate4me.com/spine-animation-for-pixijs.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)
- [How to animate game icons in Spine](https://animate4me.com/how-to-animate-game-icons-in-spine.html)
- [Animate4Me home](https://animate4me.com/)

## Make a Spine animation for your Phaser 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.
