英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论