Hi, I’m just getting up to speed with Phaser 3 with TypeScript and I can’t get spine to work.
In my game config, I define the plugin like: plugins: { scene: [ { key: 'SpineWebGLPlugin', plugin: SpineWebGLPlugin, start: true, sceneKey: 'spine' } ] },
but when I try to load a new spine in my pre-loader scene with: this.load.spine('raptor', '../../assets/spines/raptor-pro.json', '../../assets/spines/raptor.atlas');
“spine” does not seem to exist on LoaderPlugin.
Is this caused by the fact that spine definitions were not yet added to phaser.d.ts (I’m using version 3.15) ? is there a Typescript definition for the spine plugins? or can I work around the need for it?
I had the same challenge. I haven’t gotten it fully to work yet. But I got so far that I can access the loader, and see the messages in the console that the plugin was loaded:
SpineWebGLPlugin.js:9978 SpineWebGLPlugin created
SpineWebGLPlugin.js:9443 BaseSpinePlugin created
I ended with loading the plugin in the scene’s preload function:
import SpinePlugin from "./plugins/spine/SpineWebGLPlugin";
import __spineBoySkeleton from '../../assets/spine/spineboy/spineboy.json';
import __spineBoyAtlas from '../../assets/spine/spineboy/spineboy.atlas';
import __spineBoySheet from '../../assets/spine/spineboy/spineboy.png';
...
preload(): void {
...
this.load.scenePlugin(
'SpinePlugin',
SpinePlugin,
'spine');
...
}
Now I can access this.load.spine(…). However, I am still fighting with actually loading the spineboy. My method fails in the plugin when trying to access the skeleton. This is what I try:
I am also having trouble getting the spine plugin to work within typescript, the intellisense isn’t picking it up. I’ve tried the various methods I’ve seen mentioned on different examples and tutorial pages, like:
import SpinePlugin from ‘…/…/lib/SpinePlugin’;
trying referencing
the spine typings file:
///<reference path=’…/typings/spine.d.ts’ />
Nothing seems to work, and currently, there doesn’t seem to be a robust lesson or tutorial on how to set this up anywhere. Any typescript wiz-kids feel like putting one together?
Your examples are great, but would you know how to import the spine plugin from the npm package of phaser, where it is now in 3.21? I’ve been trying, in typescript, but can’t seem to get that to work properly, or get the types from there.
You’ll need a definition file declaring SpinePlugin with declaration merging to let TS know about window.SpinePlugin:
declare interface Window
{
SpinePlugin: any
}
If you update to Phaser 3.22+ then the TypeScript definition files for the SpinePlugin will be included and then you can add a definition file to your project that references them so your IDE will find them (VS Code is what I’ve tested this with).