你可以在Phaser中如何更改Spine槽或附件的颜色?

huangapple go评论95阅读模式
英文:

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

问题

我可以改变在Phaser中的Spine槽的颜色吗?(我使用的是Phaser版本3.60.0-beta.22)

我可以找到一个附件,通过创建一个新的颜色(类型为 spine.Color)来改变颜色应该是可能的,像这样:

const slot = skeleton.findSlot('slot-name');
slot.color = new spine.Color(1,1,1); // IDE没有报错,但我在运行时得到ReferenceError

然而,我得到一个运行时错误:“ReferenceError: spine is not defined”。
我按照这篇博客文章的方法在我的TypeScript项目中包含了SpinePlugin。加载和添加Spine游戏对象到场景中运行正常。我只是不知道如何创建一个新的颜色并应用它到槽中。

英文:

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

得分: 1

你可以从plugin属性中调用Color类,该属性位于*scene.spine*属性中。

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

根据评论中的问题更新:

以下是可能有些巧妙的 TypeScript 语法修复:

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

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);

huangapple
  • 本文由 发表于 2023年4月4日 15:05:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定