[RESOLVED] Still trying to figure out how to interpolate

Hi, 

I am trying to implement animations from Spine into my game.

—What I have tried—

     I looked at the example that comes with spine and it works, but it only shows how to use a single animation (or multiple but they have to be queued). I looked at the documentation and it looks like it’s for either an old build or the functions for each language are different (documentation is for java). When I try to use the functions in the interpolation section of the documentation page none of them work. 

—My Goal—

     My game is a platformed and at the moment I only have two animations: run and idle. I want it so that whenever the character moves in a direction the animation interpolates from the idle animation to the running animation. I already have the code for detecting which direction he is moving, how fast he is going etc. I just need to figure out how to change animations smoothly. I also need to be able to change how fast the animation is because I got pretty close at one point but I couldn’t change the animation speed and that made it look really bad. :frowning:

I am pretty experienced with Corona so if anyone could link me to an example or give me a snippet of code, that would be awesome! Thanks! 

[SOLUTION] I asked around and my friend Angelo got it working! :smiley: I was just editing the speed of the “currentTime” variable for the “mix” function incorrectly. Here is the working code: 

[lua]

–I had to look through the files to find these functions, the documentation said nothing about these >X(

local runAnimation = skeletonData:findAnimation(“run”) --name these whatever your animations are

local idleAnimation = skeletonData:findAnimation(“idle”)

local stateData = spine.AnimationStateData.new(skeletonData) – code for this stuff is all in the samples

stateData:setMix(“idle”, “run”, 0.9) – created the mix (crossfade) settings

stateData:setMix(“run”, “idle”, 0.9)

local function enterFrameFunction(event)

            local beta = 0.033

            local currentTime = lastTime + beta

            if math.abs(vx) < 10 then

                idleAnimation:mix(skeleton, lastTime, currentTime, true, 0, 0.2)

            else

                local value = vx

                local MAX_SPEED = 500

                if value > MAX_SPEED then

                    value = MAX_SPEED

                elseif value < -MAX_SPEED then

                    value = -MAX_SPEED

                end

                value = value / MAX_SPEED

                animSpeed = value

                if (value < 0) then 

                    print(“LEFT!”)

                    skeleton.group.xScale = -1

                    currentTime = lastTime - beta*animSpeed

                elseif (value > 0) then

                    skeleton.group.xScale = 1

                    currentTime = lastTime + beta*animSpeed

                end

                runAnimation:mix(skeleton, lastTime, currentTime, true, 0, 0.5)

            end

            local delta = currentTime - lastTime

            lastTime = currentTime

end

[/lua]

[SOLUTION] I asked around and my friend Angelo got it working! :smiley: I was just editing the speed of the “currentTime” variable for the “mix” function incorrectly. Here is the working code: 

[lua]

–I had to look through the files to find these functions, the documentation said nothing about these >X(

local runAnimation = skeletonData:findAnimation(“run”) --name these whatever your animations are

local idleAnimation = skeletonData:findAnimation(“idle”)

local stateData = spine.AnimationStateData.new(skeletonData) – code for this stuff is all in the samples

stateData:setMix(“idle”, “run”, 0.9) – created the mix (crossfade) settings

stateData:setMix(“run”, “idle”, 0.9)

local function enterFrameFunction(event)

            local beta = 0.033

            local currentTime = lastTime + beta

            if math.abs(vx) < 10 then

                idleAnimation:mix(skeleton, lastTime, currentTime, true, 0, 0.2)

            else

                local value = vx

                local MAX_SPEED = 500

                if value > MAX_SPEED then

                    value = MAX_SPEED

                elseif value < -MAX_SPEED then

                    value = -MAX_SPEED

                end

                value = value / MAX_SPEED

                animSpeed = value

                if (value < 0) then 

                    print(“LEFT!”)

                    skeleton.group.xScale = -1

                    currentTime = lastTime - beta*animSpeed

                elseif (value > 0) then

                    skeleton.group.xScale = 1

                    currentTime = lastTime + beta*animSpeed

                end

                runAnimation:mix(skeleton, lastTime, currentTime, true, 0, 0.5)

            end

            local delta = currentTime - lastTime

            lastTime = currentTime

end

[/lua]