我使用 phaser3.9 + spine-phaser-v3 加载 spine 官方 4.2.22 的示例没有问题,但无法加载同事做的 4.2.43 版本的文件,也没有任何报错毫无头绪,这是我做的最小示例能帮我看看吗?Feibuli/spine-phaser-test
无法加载同事做的 spine 文件
看起来你在使用 spine-phaser 版本 3 来加载 Spine 4.2.43 的文件。确保你使用的 spine-phaser 版本与 Spine 编辑器导出的版本一致。根据 spine-phaser 的信息,你应该使用 4.1 版本的 spine-phaser 运行时来匹配 4.1 的 Spine 编辑器版本。确保你的项目中使用的 Spine 运行时版本与导出的 Spine 文件版本一致。
你可以参考 spine-phaser 的文档 来正确加载 Spine 资产。使用 this.load.spineJson
或 spineBinary
和 spineAtlas
来加载 Spine 资产,然后使用 this.add.spine(x, y, SKELETON_NAME, ATLAS_NAME)
将其添加到场景中。
Spinebot
抱歉,我使用 v4 版本依然无法加载同事做的 spine 资产,而 spine 官方的示例 v3 v4 版本都能加载,所以应该不是我的环境有问题。我更新了 v4 版本的示例:Feibuli/spine-phaser-test,是否需要我提供 spine 源文件?
Hello nayo
Your skeleton has an empty setup pose, and the animations don’t activate any attachments.
If you want to see something, you need to activate a skin. You can use skeleton.setSkinByName
to do that.
There’s another issue with your code. You're using:
spineboy.displayHeight = (spineboy.height / spineboy.width) * 200;
But spineboy.height
and spineboy.width
are 0 because they’re calculated based on the bounds provider passed to the constructor.
If no bounds provider is passed, the SetupPoseBoundsProvider
is used. But as mentioned earlier, the setup pose is empty, so the calculated bounds are 0,0.
In this case, you should use a SkinsAndAnimationBoundsProvider
, which can take an array of skins to determine the bounds.
In short, to make your code work, you need to change it like this:
create() {
const spineboy = this.add.spine(
400,
500,
"spineboy-data",
"spineboy-atlas",
new spine.SkinsAndAnimationBoundsProvider(undefined, ["pifu/fen"]),
);
spineboy.skeleton.setSkinByName("pifu/fen");
spineboy.displayWidth = 200;
spineboy.displayHeight = (spineboy.height / spineboy.width) * 200;
this.input.enableDebug(spineboy, 0xff00ff);
spineboy.animationState.setAnimation(0, "Move", true);
}
I highly recommend to read the spine-phaser
documentation that goes throug all this concept ️