To use spine animations you will have to enable spine module.
- To do that first import it:
import SpineModuleInitialization from "../modules/spine/dist/bundle.js";
- Than install, passing module key, spineModule, and spine assets folder:
this.spineModule = this.system.installModule("spineModule", SpineModuleInitialization, "./spine/spine-assets");
- If the module was already installed, you can use systems.modules.get to retrieve it:
this.spineModule = this.system.modules.get("spineModule");
- Then canvasView should be created and registered in the module:
const canvasView = this.createCanvasView('spine-view-key');
this.spineModule.registerView(canvasView);
- After installing the module(step 2), loader will be expanded to have 3 new methods for loading spine animation files:
register() {
...
loader.addSpineJson("spine-text-key", "./spine-file.json");
loader.addSpineBinary("spine-binary-key", "./spine-file.skel");
loader.addSpineAtlas("spine-atlas", "./spine-file.atlas");
...
- ScreenPage.draw will have two new methods .spine(x,y, spine-text-key | spine-binary-key, spine-atlas) and .texture(x, y, width, height, "texture-image-key"):
init() {
const spineDrawObject = this.draw.spine(0, 0, "spine-text-key", "spine-atlas");
...
- This objects should be added to the spine view registered in the step 4:
...
this.addRenderObject('spine-view-key', spineDrawObject);
...
- Spine specific methods will be available:
spineDrawObject.scale(0.5);
spineDrawObject.animationState.setAnimation(0, "run", true);
spineDrawObject.setSkin("goblin");
- For each ScreenPage different canvasView should be created and registered in the module. Each time page starts this view should be activated:
start() {
this.spineModule.activateSpineRender('spine-view-key');
...
- After that spine objects will be rendered.