Change animation

I try to change animation in spine .

When I change the animation , the animation doesn’t change correctly.

When I pressed walk , then jump. the animation change direction.

It is not pose in the original way.

example walk is 90 degrees, but when I pressed jump , walk .

The degree changes to 80 .

but I want the animation walk with 90 degrees.

[lua]

local spine = require “spine-corona.spine”

local json = spine.SkeletonJson.new()

json.scale = 1

local skeletonData = json:readSkeletonDataFile(“examples/spineboy/spineboy.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

skeleton.group.x = display.contentWidth * 0.5

skeleton.group.y = display.contentHeight * 0.9

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–debug cabeza de chorlito

skeleton:setToSetupPose()

local bounds = spine.SkeletonBounds.new()

– AnimationStateData defines crossfade durations between animations.

local stateData = spine.AnimationStateData.new(skeletonData)

stateData:setMix(“walk”, “jump”, 0.2)

stateData:setMix(“jump”, “walk”, 0.4)

– AnimationState has a queue of animations and can apply them with crossfading.

local state = spine.AnimationState.new(stateData)

–state:setAnimationByName(0, “drawOrder”)

–state:addAnimationByName(0, “jump”, false, 0)

state:addAnimationByName(0, “walk”, 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”)

Runtime:addEventListener(“enterFrame”, function (event)

– Compute time in seconds since last frame.

local currentTime = event.time / 1000

local delta = currentTime - lastTime

lastTime = currentTime

– Bounding box hit detection.

bounds:update(skeleton, true)

if bounds:containsPoint(touchX, touchY) then

headSlot.g = 0;

headSlot.b = 0;

else

headSlot.g = 1;

headSlot.b = 1;

end

– Update the state with the delta time, apply it, and update the world transforms.

state:update(delta)

state:apply(skeleton)

skeleton:updateWorldTransform()

end)

–local object = display.newCircle( 100, 100, 30 )

–object:setFillColor( 0.5 )

local jump = display.newCircle( 100, 100, 30 )

jump.id = “ball object”

–I pressed this button and jumps

function jump:touch( event )

    if event.phase == “began” then

        print( "Touch event began on: " … self.id )

        – set touch focus

        display.getCurrentStage():setFocus( self )

        self.isFocus = true

state:addAnimationByName(0, “jump”, true, 0)

    elseif self.isFocus then

        if event.phase == “moved” then

            print( “Moved phase of touch event detected.” )

        elseif event.phase == “ended” or event.phase == “cancelled” then

            – reset touch focus

            display.getCurrentStage():setFocus( nil )

            self.isFocus = nil

        end

    end

    return true

end 

jump:addEventListener( “touch”, jump )

local walk = display.newCircle( 80, 400, 30 )

walk.id = “ball object”

– I pressed this button and walk

function walk:touch( event )

    if event.phase == “began” then

        print( "Touch event began on: " … self.id )

        – set touch focus

        display.getCurrentStage():setFocus( self )

        self.isFocus = true

state:addAnimationByName(0, “walk”, true, 0)

    elseif self.isFocus then

        if event.phase == “moved” then

            print( “Moved phase of touch event detected.” )

        elseif event.phase == “ended” or event.phase == “cancelled” then

            – reset touch focus

            display.getCurrentStage():setFocus( nil )

            self.isFocus = nil

        end

    end

    return true

end 

walk:addEventListener( “touch”, walk )

Runtime:addEventListener(“touch”, function (event)

if event.phase ~= “ended” and event.phase ~= “cancelled” then

– Make the coordinates relative to the skeleton’s group.

touchX = event.x - skeleton.group.x

touchY = skeleton.group.y - event.y

else

touchX = 999999

touchY = 999999

end

end)

[/lua]