Switching sprites sequence with touch Run, Jump Up, Jump Down

Hello everyone,

I’ve trying to create an animation. The basic idea is a character running on a platform, then when touch occur, the character will jump up, and he will jump back down. So my goal is to change from running, to jump up, then jump down, then running again when hit the platform.

The code that I have so far, he will change to jump up, but hit and miss to jump down. Also, he won’t run again.

Thank you in advance.

function scene:createScene(event) sheetData = { width = 100, height = 100, numFrames = 49, sheetContentWidth = 700, sheetContentHeight = 700, } playerSheet = graphics.newImageSheet( "sprites99.png", sheetData ) sequenceData = { { name="run", start=3, count=14, time= 700 }, { name="slash", start=41, count=9, time=500 }, { name="jump", frames={23, 24}, time=500 }, { name="jump2", start=22, count=5, time= 500}, { name="walk", start=4, count=3, time=800 }, { name="jumpDown", start=28, count=5, time= 800} } animation = display.newSprite( playerSheet, sequenceData ) animation.xScale, animation.yScale = 2, 2 animation.anchorX = 0.5 animation.anchorY = .5 animation.x = display.contentCenterX -400 animation.y = display.contentCenterY physics.addBody(animation, "static", {density=.1, bounce=0.1, friction=1}) animation:applyForce(0, -300, animation.x, animation.y) animation:setSequence( "run" ) animation:play() screenGroup:insert(animation) end function jump(event) if event.phase == "began" then animation.bodyType = "dynamic" animation:applyForce(1, -600, animation.x, animation.y) local vx,vy = animation:getLinearVelocity() if vy \< 0 then animation:setSequence("jump"); animation:play() print "jumping" end if vy \> 0 then animation:setSequence("jumpDown"); animation:play() print "jumping down" end end function onCollision( event ) if ( event.phase == "began" ) then animation:setSequence( "run" ) end end function scene:enterScene(event) Runtime:addEventListener("touch", jump) Runtime:addEventListener("collision", onCollision) end

Still trying to get this working since yesterday, but still not what i really want. Any suggestion, clue or hint would be appreciated.

Thanks.

So your looking for something like this (pseudo code and general idea below)

First:
Set flag on player: something like player.isJumping = false

After:

  1. User touches screen -> play jump animation.
    Set isJumping flag to true

  2. Player jump animation ends or player reaches allotted jump height -> play jump down animation.

  3. Player hits ground (in collision handler) -> check if isJumping == true, if so play running animation then set isJumping to false.

  4. rinse and repeat.

Thank you Gremlin. I appreciate the idea.

Still trying to get this working since yesterday, but still not what i really want. Any suggestion, clue or hint would be appreciated.

Thanks.

So your looking for something like this (pseudo code and general idea below)

First:
Set flag on player: something like player.isJumping = false

After:

  1. User touches screen -> play jump animation.
    Set isJumping flag to true

  2. Player jump animation ends or player reaches allotted jump height -> play jump down animation.

  3. Player hits ground (in collision handler) -> check if isJumping == true, if so play running animation then set isJumping to false.

  4. rinse and repeat.

Thank you Gremlin. I appreciate the idea.