Hi!
I'm setting/adding animations successfully on track 0 using the Spine Library in Solar2D. But I don't understand the concept of an "empty" animation, and I am having trouble understanding how to blend between any two of my animations. I have read the docs on setEmptyAnimation (http://esotericsoftware.com/spine-api-reference#AnimationState-setEmptyAnimation).
As I understand it, the following pseudocode should blend smoothly from a "walk" animation on track 0, to a "run" animation on track 1, and then to "jump", a different animation which replaced "walk" on track 0.
animationState.setAnimationByName(0, "walk", -1)
---
start walking forever (-1 loops)
wait(5)
---
let it walk for 5 seconds
animationState.setAnimationByName(1, "run", -1)
---
tell the animation to play "run" on track 1 forever (-1 loops)
animationState.setEmptyAnimation(1, 2)
---
take 2 seconds to mix to track 1, where "run" is playing
wait(3)
---
wait for 3 seconds, meaning it will be completely in the "run" animation for 1 second, because of the 2 second mixTime
animationState.setAnimationByName(0, "jump", -1)
---
track 0 will now play "jump", not "run"
animationState.setEmptyAnimation(0, .2)
---
take .2 seconds to mix to track 0, where "jump" is playing
This doesn't seem to work as intended. Should it?
I can't tell exactly what the "setEmptyAnimation" does. What does "empty" mean? Is it the track that is currently not playing? Or the one that is currently playing, but that will be "empty" because you're mixing out from it? I'm confused. Help!
Here's the function I've currently got which I think should do this correctly (it's in Lua). It alternates between track 0 and 1, with whatever animation you request:
local playOnZeroTrack = true
function spineObject:blendToNewAnimation(animationName, mixDuration, loops)
local emptyTrack = playOnZeroTrack and 0 or 1
local newTrack = playOnZeroTrack and 1 or 0
animationState:setAnimationByName(newTrack, animationName, loops)
animationState:setEmptyAnimation(emptyTrack, mixDuration)
print("Empty animation set to track ", emptyTrack, "new animation set to track ", newTrack )
playOnZeroTrack = not playOnZeroTrack
end
With this code, it blends smoothly to an animation on track 1, but when I try to go back to track 0, it snaps and goes immediately. How do I get it to go both ways? Is this possible with only two tracks? why not? Here's a video showing what the above code does.