How can I change the color of a Spine slot or attachment in Phaser?

154 views Asked by At

How can I change the color of a Spine slot in Phaser? (I'm using Phaser version 3.60.0-beta.22)

I can find an attachment, and it should be possible to change the color by creating a new color (of the type spine.Color) like this:

const slot skeleton.findSlot('slot-name');
slot.color = new spine.Color(1,1,1); // IDE doesn't complain, but I get ReferenceError at runtime

However, I get a runtime error: "ReferenceError: spine is not defined". I followed this blog post to include the SpinePlugin in my TypeScript project. Loading and adding Spine game objects to the scene work fine. I just don't know how to create a new Color and apply it to the slot.

1

There are 1 answers

4
winner_joiner On BEST ANSWER

You can call the Color Class from the plugin property, of the scene.spine property

slot.color = new this.spine.plugin.Color(1, 1, 1);

Update (based on question in the comment):

Here possible hacky typescript syntax fix:

slot.color = new (this as any).spine.plugin.Color(1, 1, 1);