• Editor
  • What is Animation.mix for in Corona runtime?

I noticed that the Corona runtime has an Animation.mix() method, but this doesn't exist in the C++ runtime... is that because the C++ runtime is a work in progress?

Related Discussions
...

Hmmm and it doesn't look like it's used anywhere?

Animation.mix is used to blend animations together, for example for smooth transitions between animations. You first use apply to set the base animation and then call mix with another animation to blend them together, with the alpha argument (between 0 and 1) being the blend factor. mix does indeed appear to be missing from the C++ runtime.

I copied animation.mix over to the C++ runtime (in my local copy) and it worked perfectly. Nate already had all the required functionality built into animation.apply. From there it was a pretty simple step to add transitions to my animation system.

This was the final thing I needed to match features with my own skeletal animation system. (I wrote Demina, and I'm happy to retire it. Turns out I'd rather work on games than tools. 🙂

2 months later

Can you show the Corona Code for mixing, or tell me what I'm doing wrong?

I'm just trying to mix into the idle animation from the walk. It does play but it snaps into it.

...snippet
local skeletonData = json:readSkeletonDataFile("data/spineboy.json")
local idleAnimation = skeletonData:findAnimation("idle")
local walkAnimation = skeletonData:findAnimation("walk")

...snippet
        count=count+1
        if(count<120)then
            walkAnimation:apply(skeleton, animationTime, true)
        else
            //simply trying to smoothy switch to the idle
            idleAnimation:mix(skeleton, animationTime, true,.5) 
        end

Figured it out.

            blendIn=blendIn+.03
            if(blendIn>1)then
               idleAnimation:apply(skeleton, animationTime, true) 
            else
            walkAnimation:apply(skeleton, animationTime, true)
            idleAnimation:mix(skeleton, animationTime, true,blendIn)                
end

Full code

local spine = require "spine-corona.spine"

local json = spine.SkeletonJson.new()
json.scale = 1
local skeletonData = json:readSkeletonDataFile("data/spineboy.json")
local idleAnimation = skeletonData:findAnimation("idle")
local walkAnimation = skeletonData:findAnimation("walk")

local skeleton = spine.Skeleton.new(skeletonData)
function skeleton:createImage (attachment)
	

---

 Customize where images are loaded.
	return display.newImage("data/" .. attachment.name .. ".png")
end
skeleton.x = 150
skeleton.y = 325
skeleton.flipX = false
skeleton.flipY = false
skeleton.debug = false 

---

 Omit or set to false to not draw debug lines on top of the images.
skeleton:setToBindPose()

local lastTime = 0
local animationTime = 0
local count=0
local blendIn=0
Runtime:addEventListener("enterFrame", function (event)
	

---

 Compute time in seconds since last frame.
	local currentTime = event.time / 1000
	local delta = currentTime - lastTime
	lastTime = currentTime
        
count=count+1 --- Accumulate time and pose skeleton using animation. animationTime = animationTime + delta
if(count<120)then walkAnimation:apply(skeleton, animationTime, true) else blendIn=blendIn+.03 if(blendIn>1)then idleAnimation:apply(skeleton, animationTime, true) else walkAnimation:apply(skeleton, animationTime, true) idleAnimation:mix(skeleton, animationTime, true,blendIn) end end skeleton:updateWorldTransform() end)