• International中文
  • 在android中如何切换显示不同的spine动画

我想通过libgdx在android中来展现spine动画。
我的应用场景是假如我有A,B,C,D四个spine动画,在不同的时刻我需要组合显示它们,可能是A和B同时展现,也可能是多个A和其他动画同时展现。我查找了github上几乎所有关于在android上通过libgdx来播放spine动画的项目,但都没找到类似场景的。

    Related Discussions
    ...

    csbz17027 I am not familiar with libgdx, but it seems what you want to do is play the animation at different times, I think you can just change the animationStart property of TrackEntry. By default this is set to 0, so the animation will start playing at the 0 second mark of the animation, but changing it will allow you to start playing in the middle of the animation.
    I hope this will help you.

      Misaki Thank you for your answer. But I don't want to change the playback of a certain spine animation, I need to play different spine animations at different times. For example, at the beginning, I was playing animation A, and then I needed to remove animation A and play several B and C animations.

        csbz17027 We will reply in English, but you are welcome to write in your native language. This forum has a translate button so we can read the posts through it.


        I need to play different spine animations at different times

        So are you simply wanting to queue animations? To queue animations to play in the future, call addAnimation.
        addAnimation can set a delay, e.g. to start playing an animation 3 seconds after the previous animation has started playing.

          Misaki 好的。我说的切换不是说切换一个spine内的不同动画。

          在上图中,我有两个spine,一开始我在页面显示了一个CLASSIC_1,然后我需要移除CLASSIC_1,然后显示多个GOLD_1。

            csbz17027 So what you are looking for is a way to instantiate the GOLD_1 skeleton at runtime? (By the way, note that what you call a spine is generally called a skeleton).
            I am not sure yet, but it seems that the general API of Spine Runtimes does not provide a way to instantiate skeletons at runtime, so you may need to instantiate the GOLD_1 skeleton when the CLASSIC_1 is instantiated, and then hide it until the animation is actually needed.
            I would appreciate it if you could wait for a more detailed answer until other staff can confirm this.

            In spine-libgdx (and many other runtimes) you load your skeleton data, create a skeleton from it, pose the skeleton with 1 or more animations, and render it. You can have multiple skeleton instances for the same skeleton data if you want, so you can pose them differently.

            To pose skeletons with 1 or more animations, you use an AnimationState instance. Usually each skeleton gets its own AnimationState, as that tracks the animation times for that skeleton.

            This is all explained in the runtimes user guide:
            https://esotericsoftware.com/spine-runtimes-guide
            In case that link shows up in English, here's a link to the user guide in Chinese:
            https://zh.esotericsoftware.com/spine-runtimes-guide

            Also see the spine-libgdx examples:
            EsotericSoftware/spine-runtimestree/4.2/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine
            Start with SimpleTest1.

            In spine-libgdx your own code draws the skeletons, so you control when each one gets drawn.