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