Hey guys and girls, I am working on a game where I spawn enemies, some of them are made with spine some are not. but i need a way to address all enemies from the same table like - 'enemies[1]'. the problem is wen i use spine i want sometimes only one attachment from the whole model to be an enemy. like if an enemy has a rope then the rope does not count only the body. For some reason there is a gap of time since i call the spine object using the function below. i mean everything inside the function is called on time but for some reason the 'FUNCTION BODY:CREATEIMAGE(ATTACHMENT) ' is called after a while and i can't see why. so when i try addressing that enemy it tells me it's a 'nil' value.
Please any help would be appreciated. I need to know what is causing the delay and how to fix it.
This is the function to generate the spine object:
local function spwnEnemy(tpe)
local skeletonData = json:readSkeletonDataFile("images/spine/" .. tpe .. "/" .. tpe .. ".json")
local body = spine.Skeleton.new(skeletonData)
function body:createImage (attachment)
---
This function is called with some delay for some reason
if(attachment.name=="OpenEyes" and tpe=="Character") then
local numLst = #spriteTable+1;
spriteTable[numLst] = display.newSprite(thisS, thisD)
return spriteTable[numLst]
else
---
used when spawning an enemy:
if(attachment.name~="Layera") then
local thisImage = display.newImage("images/spine/" .. tpe .. "/" .. attachment.name .. ".png");
return thisImage
else
local a= #enemies+1;
enemies[a] = display.newImage("images/spine/Keke/Layera.png");
enemies[a].state = "free";
return enemies[a];
end
end
end
body.group.y = _H/2
body.group.pause = "no"
body.group.crntAnime = ""
body.group.isActive = "no";
body.flipX = false
body.flipY = false
body.debug = false
---
Omit or set to false to not draw debug lines on top of the images.
body:setToSetupPose()
local pokmon = #stateTable[1]+1;
local stateData = spine.AnimationStateData.new(skeletonData)
stateTable[1][pokmon] = spine.AnimationState.new(stateData)
body.group.stNum = pokmon;
return body;
end
for t=1, 4, 1 do
kekeGrp[t] = spwnEnemy("Keke");
end