The switch of spine animation in Ulua and the method of using delegate

Source: Internet
Author: User

1. The official offer of continuous play spine animation method

Obj. Animationstate:setanimation (0, "Animation1", false)
OBJ. Animationstate:addanimation (0, "Animation2", false, 0)

Start by playing an animation, and then use Addanimation to add the animation to the back.

2. About the setanimation three parameters, you can see the prototype implementation

The second argument is the name of the animation, and the third argument is whether the animation loops and is well understood.
The first parameter, Trackindex, refers to the channel ordinal. The so-called channel track, is the animation layer, so that the character can play several spine animation at the same time. High-level channels cover low-level track: The larger the channel number, the higher the priority. I think it's like the layer concept inside PS.

3. In order to facilitate understanding of the concept of this channel, you can modify the above code.
Obj. Animationstate:setanimation (0, "Animation1", false)
Obj. Animationstate:setanimation (1, "Animation2", false)
This time will not see the playback of the Animation1, so write two animation will play simultaneously, the animation 2 is higher level, will directly cover the animation 1.

4. If you use the Addanimation method above, when the animation switch, there will be a shadow of the animation, switch to animation 2 when there is a "jump" process, looks very unnatural.

5. So on the Internet to find the cause of the residual, presumably because the spine animation internal implementation of the transition, not handled well, the solution is to play the animation before, add Settosetuppose () and Cleartracks () method.
You can use the co-process first.

Obj. Animationstate:setanimation (0, "Animation1", False)
coroutine.wait (1)
OBJ. Skeleton:settosetuppose ()
OBJ. Animationstate:cleartracks ()
OBJ. Animationstate:setanimation (0, "Animation2", false)

The test results found that there is no shadow, but animation 1 when switching animation 2, will "flash" a bit. The reason for guessing is that cleartracks () will empty the channel animation, this time the animation 1 disappears, and then immediately play animation 2, there is a very short from the disappearance to the appearance of the process.

6. This is not very good, so try to use the channel to solve, play the animation 2 when the channel Trackindex written 1, in the animation 1 play, directly in the previous layer play animation 2, which can be a good solution to the problem of residual shadow.

7. However, the processing of animation time playback using the co-process is certainly imprecise. So want to find spine animation callback method, query official documents found:

8. Then the next question is how to use the C # delegate method in Lua, and find the following method on the Ulua forum:

9. Thus, the ultimate solution to this problem is

local spineevent=obj. Animationstate:setanimation (0, "Animation1", false) Spineevent.complete = Spineevent.complete + function () OBJ. Animationstate:setanimation (1, "Animation2", true) end 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.