Spine 2D
How to use the Spine 2D integration in Pixi’VN to load skeletons, switch skins, play and combine animations, and control animation tracks.
Spine 2D is a powerful 2D animation software specifically designed for game development. It uses a skeletal animation system, meaning that characters and objects are animated through a hierarchy of bones that control the movement of attached parts.
You can learn more about Spine 2D on the official Spine 2D website.
Within your Pixi’VN project, you can use the Spine 2D integration to create complex and smooth animations for your characters and objects. This integration is essentially a wrapper around the official Spine 2D runtime for PixiJS, allowing you to use all Spine 2D features directly inside your Pixi’VN project.
Installation
To add Spine 2D to an existing Pixi’VN template (created with create-pixi-vn), run the following command in the project folder:
npm create pixi-vn@latest add spine2dIt adds the dependency to package.json and sets up main.ts, vite.config.ts and (for ink templates) the hashtag commands. If the changes cannot be applied cleanly, the project is left untouched.
To install the Spine 2D package in an existing JavaScript project, use one of the following commands:
npm install @drincs/pixi-vn-spineThe library must be imported when the game is initialized, so that it can be used inside Lazy components.
import "@drincs/pixi-vn-spine";
Game.init(body, {
// ...
});You can enable Spine 2D hashtag commands in your ink scripts by using the createSpineHandler function.
import { addBaseHashtagCommands } from "@drincs/pixi-vn-ink";
import { createSpineHandler } from "@drincs/pixi-vn-spine/ink";
addBaseHashtagCommands({ bundleIds, assetAliasIds });
createSpineHandler(); The show, edit, and remove hashtag commands can also be used with spine, just like with any other canvas element.
Pixi’VN Spine ships a set of Agent Skills that teach AI coding assistants how to correctly use the Spine 2D integration.
In LM Studio Bionic, ask the agent to install skills from
https://github.com/DRincs-Productions/pixi-vn-spine, or add the skill files in Settings → Skills. To reuse skills installed for Codex or Claude Code, enable Settings → Skills → Use skills found in other apps.
Codex:
npx skills@latest add DRincs-Productions/pixi-vn-spine@latest --skill '*' --agent codex -g -yClaude Code:
npx skills@latest add DRincs-Productions/pixi-vn-spine@latest --skill '*' --agent claude-code -g -yOther agents:
npx skills@latest add DRincs-Productions/pixi-vn-spine@latest --all -yUsage
You can use the Spine component just like any other Pixi’VN component.
However, you must first load the Spine 2D assets (skeleton and atlas) before using it.
For example:
import { Assets, canvas } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
await Assets.load(["spineboySkeleton", "spineboyAtlas"]);
const spine = new Spine({
atlas: "spineboyAtlas",
skeleton: "spineboySkeleton",
xAlign: 0.5,
yAlign: 1,
animation: "idle",
});
canvas.add("boy", spine);A Spine model can have multiple skins, and you can switch between them at runtime by using the setSkin function.
import { Assets, canvas, newLabel } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
export const startLabel = newLabel("start", [
async () => {
await Assets.load(["goblinsSkeleton", "goblinsAtlas"]);
const spine = new Spine({
atlas: "goblinsAtlas",
skeleton: "goblinsSkeleton",
skin: "goblin",
xAlign: 0.5,
yAlign: 1,
animation: "walk",
});
canvas.add("goblin", spine);
},
() => {
canvas.find<Spine>("goblin")?.setSkin("goblingirl");
},
]);There are two functions you can use to play a Spine animation: setAnimation and addAnimation.
setAnimationimmediately replaces whatever animation is currently playing on the track with the new one.addAnimationqueues the new animation so that it starts only after the current animation on the track finishes, without interrupting it.
import { Assets, canvas, newLabel } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
export const startLabel = newLabel("start", [
async () => {
await Assets.load(["spineboySkeleton", "spineboyAtlas"]);
const spine = new Spine({
atlas: "spineboyAtlas",
skeleton: "spineboySkeleton",
xAlign: 0.5,
yAlign: 1,
animation: "idle",
});
canvas.add("boy", spine);
},
() => {
canvas.find<Spine>("boy")?.addAnimation("walk", { loop: true });
},
]);You can combine Spine animations with Pixi’VN's classic motion-based animations (canvas.animate), as shown in the example below.
For more advanced games, you can also drive Spine animations directly from a ticker triggered by events, such as a button press, instead of relying only on predefined sequences.
import { Assets, canvas, newLabel } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
export const startLabel = newLabel("start", [
async () => {
await Assets.load(["spineboySkeleton", "spineboyAtlas"]);
const spine = new Spine({
atlas: "spineboyAtlas",
skeleton: "spineboySkeleton",
xAlign: 0,
yAlign: 1,
animation: "walk",
});
canvas.add("boy", spine);
canvas.animate(
spine,
[
[{ xAlign: 1 }, { duration: 1, ease: "linear" }],
[{ scaleX: -1 }, { duration: 0.2 }],
[{ xAlign: 0 }, { duration: 1, ease: "linear" }],
[{ scaleX: 1 }, { duration: 0.2 }],
],
{ repeat: Infinity },
);
},
]);It is also possible to create animation sequences by using the playSequence function.
import { Assets, canvas, newLabel } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
export const startLabel = newLabel("start", [
async () => {
await Assets.load(["spineboySkeleton", "spineboyAtlas"]);
const spine = new Spine({
atlas: "spineboyAtlas",
skeleton: "spineboySkeleton",
xAlign: 0.5,
yAlign: 1,
});
spine.playSequence([["idle", { loop: true, duration: 0.5 }], "jump"], {
repeat: Infinity,
});
canvas.add("boy", spine);
},
]);You can remove Spine animations using two methods: clearTrack, which clears the animation on a single track, and clearTracks, which clears the animations on all tracks.
import { Assets, canvas, newLabel } from "@drincs/pixi-vn";
import { Spine } from "@drincs/pixi-vn-spine";
export const startLabel = newLabel("start", [
async () => {
await Assets.load(["spineboySkeleton", "spineboyAtlas"]);
const spine = new Spine({
atlas: "spineboyAtlas",
skeleton: "spineboySkeleton",
xAlign: 0,
yAlign: 1,
animation: "walk",
});
canvas.add("boy", spine);
},
() => {
canvas.find<Spine>("boy")?.clearTracks();
},
]);