Spine
dill pixel supports the Spine format for animations. Spine is a 2D skeletal animation tool that allows you to animate 2D characters and objects in a way that is similar to how 3D animations are done. This allows for more complex animations and more efficient use of resources.
Getting Started
Section titled “Getting Started”To work with Spine in dill pixel you’ll need to enable dill pixel’s Spine plugin in your game’s configuration via the useSpine
property.
import { defineConfig } from 'dill-pixel';
export const config = defineConfig({ ... useSpine: true, ...});
Loading a Spine Animation
Section titled “Loading a Spine Animation”1. Include your spine animation in your assets:
Section titled “1. Include your spine animation in your assets:”Ensure your spine animation is included in your assets folder and you’ve configured your application’s assets for assetpack, (example below):
Directoryassets
Directoryspine{m}
- spineboy-pro.skel
- spineboy-pro.atlas
- spineboy-pro.png
2. Add the spine animation to your scene:
Section titled “2. Add the spine animation to your scene:”// import the SpineAnimation class from dill pixelimport { SpineAnimation, Scene } from 'dill-pixel';
// ensure your scene loads the spine assetsexport const assets = { preload: { bundles: ['spine'], },};
export default class SpineScene extends Scene { // declare the spine animation variable private _spine: SpineAnimation;
public async initialize() { // add the spine animation to your scene this._spine = this.add.spineAnimation({ data: 'spine/spineboy-pro.skel', animationName: 'idle', loop: true, }); }}
Playing an Animation
Section titled “Playing an Animation”To play an animation on the spine object, call .setAnimation
with the animation name, and whether the animation should loop or not:
Example:
Section titled “Example:”// Play an animationthis._spine.setAnimation('walk', true);
// or play an animation on a specific track// the track index is optional and defaults to 0 (fine for most cases)// this._spine.setAnimation('walk', true, 1);
Example:
Section titled “Example:”// Pause the animationthis._spine.paused = true;// Resume the animationthis._spine.paused = false;