使用spine-player版本是4.2.59
我的代码是这样写的:
new SpinePlayer(spineContainer.value, {
jsonUrl: '/src/assets/spine/kln_cj.json',
atlasUrl: '/src/assets/spine/kln_cj.atlas',
alpha: true,
backgroundColor: '#00000000',
premultipliedAlpha: false,
showLoading: false,
showControls: false,
viewport: {
x: -300,
y: 0,
width: 600,
height: 400,
padLeft: '5%',
padRight: '5%',
padTop: '5%',
padBottom: '5%'
},
success: function(player) {
player.play() // 开始播放动画
}
})
设置showControls: false时,我的spine动画只展示静态图片
在您的代码中,您已经正确地设置了 showControls: false
,并在 success
回调中调用了 player.play()
来开始播放动画。然而,如果动画仍然只显示静态图片,可能需要检查以下几点:
- 确保 JSON 和 Atlas 文件路径正确,并且文件内容没有损坏。
- 确保动画名称在 JSON 文件中存在,并且在
success
回调中正确设置了动画。可以通过player.animationState.setAnimation(0, "animationName", true)
来设置动画,其中"animationName"
是您想要播放的动画名称。 - 确保 SpinePlayer 的版本与导出的数据版本兼容。您使用的是 SpinePlayer 4.2.59,确保您的数据是用相同或兼容的 Spine 版本导出的。
如果这些都没有问题,您可以尝试在 success
回调中添加更多的调试信息,以确认动画状态是否正确设置。
Spinebot 我并不知道我动画名称是什么,我是通过接口拿到的json和atlas文件,存在多个animationName,该如何解决?
我并不知道我动画名称animations是什么,我是通过接口拿到的json和atlas文件,存在多个animationName,该如何设置animations
要在Spine中设置动画而不知道动画名称,您可以使用AnimationReferenceAssets
来避免直接使用动画名称。这种方法通过分配资产来工作,而不是依赖于动画名称。您可以参考spine-unity Runtime Documentation: Setting Animations来了解如何在Unity中使用AnimationReferenceAssets
。
如果您需要获取当前动画的名称,可以使用类似以下的代码来获取:
AnimationState state;
int trackIndex = 0;
TrackEntry entry = state.getCurrent(trackIndex);
String animationName;
if (entry == null)
animationName = null;
else
animationName = entry.getAnimation().getName();
这段代码可以帮助您在运行时获取当前正在播放的动画名称。
Please, do not open a new thread for a question you already did in another one. I've merge them into a single one.
There are different ways in which you can view the names of your animations. You can view them in the JSON, under the keys of the animation
object. You can import the JSON into the Spine editor and open the animation mode. Or you can directly view the names in the player by temporarily enabling the controls and clicking on the animation button:
Then, if you want to play a single animation, you can just set the default animation by using the animation config property, as explained here.
Or you can play the animation by code as Spinebot suggested.