Sorry for the late reply, I haven’t been able to code very much this week. Here is what I have so far, it still get’s the error and I still can’t figure out the cause:
[lua]
local M = {}
function M.new(scale)
– This example shows simple usage of displaying a skeleton with queued animations.
local spine = require “spine-corona.spine”
M.physicsBody = nil
local animSpeed = 1
local json = spine.SkeletonJson.new()
json.scale = scale
local skeletonData = json:readSkeletonDataFile(“examples/spineboy/skeleton.json”)
local skeleton = spine.Skeleton.new(skeletonData)
function skeleton:createImage (attachment)
– Customize where images are loaded.
return display.newImage(“examples/spineboy/images/” … attachment.name … “.png”)
end
M.physicsBody = display.newRect( -45, -250, json.scale * 170, json.scale * 500)
M.physicsBody.damage = 5
M.physicsBody.alpha = 0.01
physics.addBody(M.physicsBody, “dynamic”, {bounce = 0.2, density = 2.5, friction = 1})
M.physicsBody.isFixedRotation = true
function M.addToGroup(group)
group:insert(skeleton.group)
group:insert(M.physicsBody)
end
function M.getPhysicsBody()
return M.physicsBody
end
function M.setPlayerXScale(x)
skeleton.group.scaleX = x
end
function M.getSkeleton()
return skeleton
end
function M.setAnimSpeed( speed )
animSpeed = speed
end
skeleton.group.x = 0
skeleton.group.y = 0
skeleton.flipX = false
skeleton.flipY = false
skeleton.debug = true – Omit or set to false to not draw debug lines on top of the images.
skeleton.debugAabb = true
skeleton:setToSetupPose()
local bounds = spine.SkeletonBounds.new()
– AnimationStateData defines crossfade durations between animations.
local stateData = spine.AnimationStateData.new(skeletonData)
stateData:setMix(“idle”, “run”, 0.2)
stateData:setMix(“run”, “idle”, 0.4)
– AnimationState has a queue of animations and can apply them with crossfading.
local state = spine.AnimationState.new(stateData)
state:setAnimationByName(0, “run”, true, 0)
– local state2 = spine.AnimationState.new(stateData)
– state2:setAnimationByName(0, “run”, true, 0)
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
local lastTime = 0
local touchX = 999999
local touchY = 999999
local headSlot = skeleton:findSlot(“head”)
local hip = skeleton:findBone(“hip”)
local rep = true
function M.enterFrame (event)
– Compute time in seconds since last frame.
local currentTime = event.time / 1000
local delta = currentTime - lastTime
lastTime = currentTime
– Update the state with the delta time, apply it, and update the world transforms.
--state2:update(delta * animSpeed)
skeleton.group.x = M.physicsBody.x
skeleton.group.y = M.physicsBody.y + (M.physicsBody.height / 2)
local vx, vy = M.physicsBody:getLinearVelocity()
if (vx == 0) then
M.setAnimSpeed( 1) – 140
state:setAnimationByName(0, “idle”, true, 0)
else
M.setAnimSpeed( math.abs(vx) /300) – 140
state:setAnimationByName(0, “run”, true, 0)
end
– Bounding box hit detection.
bounds:update(skeleton, true)
state:update(delta * animSpeed)
state:apply(skeleton)
skeleton:updateWorldTransform()
end
end
return M
[/lua]