pixijs / spine

Pixi.js plugin that enables Spine support.
Other
570 stars 217 forks source link

Bug: pixi-spine does not register its loaders to pixi.js-legacy #522

Closed f0nar closed 1 year ago

f0nar commented 1 year ago

I cannot use pixi.js-legacy with pixi-spine. If I run next code snippet

import 'pixi-spine';
import * as PIXI from "pixi.js-legacy";
import { Spine } from "pixi-spine";

PIXI.extensions

const run = async () => {
  const app = new PIXI.Application<HTMLCanvasElement>({
    background: "#1099bb",
    resizeTo: window
  });

  document.body.appendChild(app.view);

  PIXI.Assets.add('spineData', 'skeleton.json');
  PIXI.Assets.add('spineAtlas', 'skeleton.atlas');
  await PIXI.Assets.load(['spineData', 'spineAtlas']).then(console.log); // check screenshot with output below

  const spineResource = PIXI.Assets.get('spineData');
  const spine = new Spine(spineResource.spineData);
  app.stage.addChild(spine);

  const bounds = spine.getBounds(true);

  spine.position.set((app.view.width - bounds.width) / 2 - bounds.left, (app.view.height - bounds.height) / 2 - bounds.top);
  spine.state.setAnimation(0, "animation", true);
  spine.autoUpdate = true;
};

run();

I receive errors in the console due to unparsed data and next object in console image As you can see that atlas is not parsed at all and spine json file is loaded as simple json and it does not have spineData property. As I understood, problem is that pixi-spine registers its loaders not to the same extensions package that pixi.js-legacy uses. As quick fix I exported atlas and spine loaders extensions from pixi-spine and called PIXI.extensions.add with them in my index.ts, where PIXI is pixi.js-legacy import. FYI: The same is relevant to https://github.com/miltoncandelero/spine-runtimes/tree/spine-pixijs/spine-ts/spine-pixi

I would like to have ability to simply use pixi-spine with pixi.js-legacy or have exports in pixi-spine to register loaders manually

You can use my repo for testing https://github.com/f0nar/pixi.js-legacy-pixi-spine/tree/main

Duplicated from pixi issue https://github.com/pixijs/pixijs/issues/9779