Hello again.
I am working on a game project where I started using spawning function that calls
for a creature to be placed on the screen every X seconds.
With attempting to try Spine as my main animation controller I need to rework my
functions as well, so I tried something like that:
local enmDISgroup = display.newGroup();
---
local enmTable = {};
local json = spine.SkeletonJson.new()
json.scale = 0.2
---
ENM1:
local stateTable = {};
local function spwnEnm(tpe, num)
local skeletonData = json:readSkeletonDataFile("examples/spineboy/" .. tpe .. ".json")
local enm = spine.Skeleton.new(skeletonData)
function enm:createImage (attachment)
print(attachment.name);
local thisImage = display.newImage("examples/spineboy/images/" .. attachment.name .. ".png");
return thisImage
end
enm.group.x = _W/2
enm.group.y = _H/2
enm.group.num = 1
enm.group.pause = "no"
enm.flipX = false
enm.flipY = false
enm.debug = false
---
Omit or set to false to not draw debug lines on top of the images.
enm:setToSetupPose()
local stateData = spine.AnimationStateData.new(skeletonData)
stateTable[num] = spine.AnimationState.new(stateData)
enmDISgroup:insert(enm.group);
return enm;
end
During the game time I call for function: "enmTable[1] = spwnEnm("spineboy", 1);"
I also sets it's animation : "stateTable[1]:setAnimationByName(0, "jump", true, 0);"
and at ENTERFRAME function i call for:
[code]for st=1, #stateTable, 1 do
if(stateTable[st]~=nil) then
stateTable[st]:update(delta)
stateTable[st]:apply(enmTable[st])
enmTable[st]:updateWorldTransform()
end
end
[/code]
In other parts of the code I call for changing attachments (for e.g: changing a shirt, or adding a hat):
"enmTable[1]:setAttachment("hat", "hat");"
My question
Is this way afficient or can it cause problems with memory and performance?
I mean what other way can I use to make it better? because right now it's working fine.
Thanks ahead, Saiphan.