Arrrgh! not sure why it’s not working.
Yes, SuperiBot is iOS only, if you can get ahold of a device download the free “Lite” version.
Take a look at this YouTube video…
SuperiBot
Not sure what the “Mix” runtime does, maybe does what I created myself, because I’m constantly mixing different animations for my iBot.
There is one thing I call in my function to set up the animation that isn’t in my “playAnimation” update function that I believe you need.
[lua]MySpine.animationTime = 0[/lua]
animationTime needs to be reset before calling the update function with a runtime listener.
In my function that loads the next animation to play, I load the params for a new animation from my table , I’m doing something similar what you are doing, but instead of doing a “if/else” statement, I’ve got a table of all my animations setup and I reference the Index number to the animation I want to play from some function that calls for a new animation.
So, something happens in my game (jump for instance) and a function in my “main.lua” which has required “MySpine.lua”, sets the animation index needed as MySpine.AnimationIndex = 3 for instance (this jumps LEFT and loops/ see table).
Here’s what my table looks like that resides in MySpine.lua.
[lua]
local Animation = {}
Animation[1] = {}
Animation[1].Skeleton = “data/skeleton-Jump1.json” --default animation/pose
Animation[1].flipX = true
Animation[1].Loop = true
Animation[2] = {}
Animation[2].Skeleton = “data/skeleton-Jump1.json” --default animation/pose
Animation[2].flipX = false
Animation[2].Loop = true
Animation[3] = {}
Animation[3].Skeleton = “data/skeleton-Jump2.json”
Animation[3].flipX = true
Animation[3].Loop = true
Animation[4] = {}
Animation[4].Skeleton = “data/skeleton-Jump2.json”
Animation[4].flipX = false
Animation[4].Loop = true
Animation[5] = {}
Animation[5].Skeleton = “data/skeleton-Walk.json”
Animation[5].flipX = true
Animation[5].Loop = true
Animation[6] = {}
Animation[6].Skeleton = “data/skeleton-Walk.json”
Animation[6].flipX = false
Animation[6].Loop = true
Animation[7] = {}
Animation[7].Skeleton = “data/skeleton-Standing.json”
Animation[7].flipX = true
Animation[7].Loop = false
[/lua]
You can see in my update function “playAnimation”, I set the Index to the MySpine.AnimationIndex that has been called.
[lua]
local lastTime = 0
–local animationTime = 0
function playAnimation(event)
--print(“playAnimation Runtime is loaded”)
local Index = MySpine.AnimationIndex
skeleton.x = MySpine.PlayerDemoX
skeleton.y = MySpine.PlayerDemoY
--skeleton.flipX = MySpine.flipX
skeleton.flipX = MySpine.flipX
local currentTime = event.time / 1000
local delta = currentTime - lastTime
lastTime = currentTime
MySpine.animationTime = MySpine.animationTime + delta
walkAnimation:apply(skeleton, MySpine.animationTime, Animation[Index].Loop)
skeleton:updateWorldTransform()
end
[/lua]
You can see how I commented out reseting the animationTime = 0 above the function. It needs to be reset at the start of each new animation and I moved it to that function.
Here’s how I load a new animation to the “start” of a level. It creates the display group to show the animation. The display group holding the SuperiBot Spine animation gets destroyed when the level is completed or changed.
I left the commented lines in as some either didn’t work as expected or were moved to other functions.
[lua]
function MySpine.loadAnimation() --called when new Level loads
if AnimationPlaying == true then
AnimationPlaying = false
Runtime:removeEventListener(“enterFrame”, playAnimation)
end
MySpine.EnableRocket = false
MySpine.Shooting = false
MySpine.StashGunAndRun = false
local Index = MySpine.AnimationIndex
– json.scale = 1.2
print(“loadAnimation() has been called”)
MySpine.PlayerGroup = display.newGroup()
MySpine.PlayerGroup.isVisible = true
skeleton = spine.Skeleton.new(skeletonData, MySpine.PlayerGroup)
skeleton:setToBindPose()
skeleton.x = MySpine.PlayerDemoX
skeleton.y = MySpine.PlayerDemoY
– iBot SIZE determined in loadDemoMap.lockMapDemoStep2() !!!
--skeleton.xScale = .8
--skeleton.yScale = .8
skeleton:rotate(MySpine.PlayerDemoRotate)
skeleton.flipX = false
skeleton.flipY = false
skeleton.debug = false
--camera:add(MySpine.PlayerGroup, 1, false)
print(“MySpine.PlayerGroup = display.newGroup() Called>>>>>>>>>>>>>>”)
print(“loadAnimation() has been called Flag2”)
--[[ if AnimationPlaying == true then
– AnimationPlaying = false
Runtime:removeEventListener(“enterFrame”, playAnimation)
end --]]
AnimationPlaying = true
--MySpine.PlayerGroup.isVisible = true
--MySpine.PlayerGroup:toFront()
--walkAnimation = json:readAnimationFile(skeletonData, “data/skeleton-Jump2.json”)
MySpine.flipX = Animation[Index].flipX
MySpine.animationTime = 0 --reset it here
--skeleton.flipX = Animation[Index].flipX
walkAnimation = json:readAnimationFile(skeletonData, Animation[Index].Skeleton)
MySpine.PlayerGroup:toFront()
Runtime:addEventListener(“enterFrame”, playAnimation)
--end
print(“loadAnimation() has been called Flag3”)
end
[/lua]
Now here’s how I load the subsequent animations to be played since the display group has been created.
Realize Ima newb and the code isn’t optimized or perfect, but it works.
[lua]
function MySpine.callAnimation() --called to load 2nd or more animation
if AnimationPlaying == true then
AnimationPlaying = false
Runtime:removeEventListener(“enterFrame”, playAnimation)
end
local Index = MySpine.AnimationIndex
MySpine.flipX = Animation[Index].flipX
print(“callAnimation() has been called”)
if MySpine.Shooting == true then --code to stand up from shooting
MySpine.Shooting = false
if MySpine.flipX == true then
MySpine.AnimationIndex = 13 --sets Index for NEXT walk animation
Index = 13
elseif MySpine.flipX == false then
MySpine.AnimationIndex = 14 --sets Index for NEXT walk animation
Index = 14
end
end
--print(“callAnimation() has been called Flag2”)
--if AnimationPlaying == true then
– AnimationPlaying = false
– Runtime:removeEventListener(“enterFrame”, playAnimation)
– end
AnimationPlaying = true
MySpine.PlayerGroup.isVisible = true
--MySpine.PlayerGroup:toFront()
--skeleton.x = MySpine.PlayerDemoX
--skeleton.y = MySpine.PlayerDemoY
MySpine.animationTime = 0 --reset it here!
--walkAnimation = json:readAnimationFile(skeletonData, “data/skeleton-Jump2.json”)
--skeleton.flipX = Animation[Index].flipX
walkAnimation = json:readAnimationFile(skeletonData, Animation[Index].Skeleton)
Runtime:addEventListener(“enterFrame”, playAnimation)
--end
--print(“callAnimation() has been called Flag3”)
end
[/lua]
Lots to digest here, but should get you going. Loading the animations from a table is the way to go IMO.
Let me know if this get you going. If not I’ll post more of my MySpine.lua.
Hope this helps,
Nail