I've done some stuff to find an issue to spawn all skeleton (CORONA SDK) I need on screen, putting them into different table, doing some loop.
So all my skeleton are displayed but just one is animated, I don't know why ( see code below here ), should be mistake with the runtime listener, can't figure out.
what the workflow to spawn different skeleton with spine in just one runtime ? It's weird I could'nt find someting talking about it ..
Runtime Corona :
local spine = require "spine-corona.spine"
local Vague = 1
local Player
local SkeletonGame = {}
local GetAnim
local SkeletonChoice = {"Mouds","Kehops"}
local AnimationChoice = {"Walking","Walk"}
local LoopChoice = {true,true}
local PlayerFlipX = {false,false}
local PlayerFlipY = {false,false}
local SkeletonLevel = {
{Level = {1,2}},
{Level = {1,2}},
}
local function DisplaySkeleton (Vague)
if SkeletonGame ~= {} then
for x = #SkeletonGame, 1, -1 do
display.remove( SkeletonGame[x] )
SkeletonGame[x] = nil
end
SkeletonGame = {}
end
local skeletonLevel = SkeletonLevel[Vague]
local skeleton = skeletonLevel.Level
---
LOOP to make all the skeletons
for x = 1, #skeleton do
local skeletonIndex = skeleton[x]
local json = spine.SkeletonJson.new()
local SkeletonData = json:readSkeletonDataFile("spine-animation/"..SkeletonChoice[skeletonIndex].."/skeleton.json")
Player = spine.Skeleton.new(SkeletonData)
Player.group.x = math.random(200,1200)
Player.group.y = math.random(200,700)
Player.flipX = PlayerFlipX[skeletonIndex]
Player.flipY = PlayerFlipY[skeletonIndex]
Player.debug = false
---
Omit or set to false to not draw debug lines on top of the images.
Player.debugAabb = true
Player:setToSetupPose()
function Player:createImage (attachment)
local PlayerBox = display.newImage("spine-animation/".. SkeletonChoice[skeletonIndex] .."/images/".. attachment.name .. ".png")
return PlayerBox
end
SkeletonGame[#SkeletonGame+1] = Player.group
SkeletonGame.name = "Skeleton : " ..SkeletonChoice[skeletonIndex]
print(SkeletonGame.name)
---
ANIMATION STATE
local stateData = spine.AnimationStateData.new(SkeletonData)
local state = spine.AnimationState.new(stateData)
state:setAnimationByName(0, AnimationChoice[skeletonIndex], LoopChoice[skeletonIndex],0)
Player:updateWorldTransform()
state.onStart = function (trackIndex)
print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name)
end
state.onEnd = function (trackIndex)
print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name)
end
state.onComplete = function (trackIndex, loopCount)
print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount)
end
state.onEvent = function (trackIndex, event)
print(trackIndex.." event: "..state:getCurrent(trackIndex).animation.name..", "..event.data.name..", "..event.intValue..", "..event.floatValue..", '"..(event.stringValue or "").."'")
end
---
LOOP ANIMATION ENTERFRAME
local lastTime = 0
function GetAnim(event)
local currentTime = event.time / 1000
local delta = currentTime - lastTime
lastTime = currentTime
state:update(delta)
state:apply(Player)
Player:updateWorldTransform()
end
---
]]
Runtime:addEventListener("enterFrame", GetAnim)
end
end
DisplaySkeleton(Vague)
Should I do like that ? Or there is an easy way to display more than one skeleton ?
Update : Should I put all my skeleton in the same project and display them when I need them as Nate tell here ?http://esotericsoftware.com/forum/viewtopic.php?f=11&t=2377&p=11782&hilit=skeleton#p11782