# spawn skeletons

**URL:** <https://forums.solar2d.com/t/spawn-skeletons/324239>\
**Category:** Spine\
**Created:** [April 3, 2014, 2:03pm UTC](https://forums.solar2d.com/t/spawn-skeletons/324239 "2014-04-03T14:03:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julio\_DeVega](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/41988e/32.png) [@Julio\_DeVega](https://forums.solar2d.com/u/Julio_DeVega)\
**Post date:** [April 3, 2014, 2:03pm UTC](https://forums.solar2d.com/t/spawn-skeletons/324239/1 "2014-04-03T14:03:19Z")

</div>

I’ve done some stuff &nbsp;to find an issue to spawn all skeleton I need on screen, putting them into different table, doing some loop.&nbsp;

So all my skeleton are display but just one is animated, &nbsp;I don’t know why ( see code below here )

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 :&nbsp;

```
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 = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Level = {1,2}}, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {Level = {1,2}}, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; local function DisplaySkeleton (Vague) &nbsp; &nbsp; &nbsp; &nbsp;if SkeletonGame ~= {} then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x = #SkeletonGame, 1, -1 do &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display.remove( SkeletonGame[x] ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SkeletonGame[x] = nil &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SkeletonGame = {} &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local skeletonLevel = SkeletonLevel[Vague] &nbsp;&nbsp;&nbsp;&nbsp;local skeleton = skeletonLevel.Level --LOOP to make all the skeletons&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for x = 1, #skeleton do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local skeletonIndex = skeleton[x] &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local json &nbsp; &nbsp; = spine.SkeletonJson.new() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local SkeletonData &nbsp; &nbsp;= json:readSkeletonDataFile("spine-animation/"..SkeletonChoice[skeletonIndex].."/skeleton.json") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player &nbsp; &nbsp;= spine.Skeleton.new(SkeletonData) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.group.x = math.random(200,1200) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.group.y = math.random(200,700) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.flipX = PlayerFlipX[skeletonIndex] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.flipY = PlayerFlipY[skeletonIndex] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.debug = false -- Omit or set to false to not draw debug lines on top of the images. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player.debugAabb = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Player:setToSetupPose() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; function Player:createImage (attachment) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local &nbsp;PlayerBox = display.newImage("spine-animation/".. SkeletonChoice[skeletonIndex] .."/images/".. attachment.name .. ".png") &nbsp; &nbsp; return PlayerBox end &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SkeletonGame[#SkeletonGame+1] = Player.group &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SkeletonGame.name = "Skeleton : " ..SkeletonChoice[skeletonIndex] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print(SkeletonGame.name) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --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) &nbsp;&nbsp;&nbsp;&nbsp;print(trackIndex.." start: "..state:getCurrent(trackIndex).animation.name) end state.onEnd = function (trackIndex) &nbsp;&nbsp;&nbsp;&nbsp;print(trackIndex.." end: "..state:getCurrent(trackIndex).animation.name) end state.onComplete = function (trackIndex, loopCount) &nbsp;&nbsp;&nbsp;&nbsp;print(trackIndex.." complete: "..state:getCurrent(trackIndex).animation.name..", "..loopCount) end state.onEvent = function (trackIndex, event) &nbsp;&nbsp;&nbsp;&nbsp;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) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;local currentTime = event.time / 1000 &nbsp; &nbsp;local delta = currentTime - lastTime &nbsp; &nbsp;lastTime = currentTime &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;state:update(delta) &nbsp; &nbsp;state:apply(Player) &nbsp; &nbsp;Player:updateWorldTransform() end--]] Runtime:addEventListener("enterFrame", GetAnim) &nbsp;end &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DisplaySkeleton(Vague) &nbsp;

```

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; Should I do like that ? Or there is an easy way to display more than one skeleton ?

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
