Basically what i’m trying to do, is when the character is moving left or right, i want to play the “Left” and “Right” animation that i have created in my sprite sheet, the problem is when i try to call the animation, it only play 1 frame, this is what i have:
Set Animation Based on Speed
local function setHeroAnimation() local vx, vy = dan:getLinearVelocity() if vx \< 5 then -- if x velocity less than 5 play the standing animation hero:setSequence( "Parado" ) else hero:setSequence( "Run" ) -- x velocity higher than 5 play the run animation end end
Spritesheet configuration
local myImageSheet = graphics.newImageSheet( "run.png", sheetInfo:getSheet() ) local sequenceData = {{ name = "Run", frames = {6,7,8,9,10,11,12,13,14,15,16,17} , time = 800}, { name = "Parado", frames = {1,2,3,4,5} , time = 900}}
This is the hero:
hero = display.newSprite( myImageSheet, sequenceData ) hero.x = 90 hero.y = 210 hero.isFixedRotation = true physics.addBody( hero, "dynamic", physicsData:get("hero") ) hero:play()
enterFrame Listener
Runtime:addEventListener( "enterFrame", setHeroAnimation )
When i move the character, the image changes for the first frame of the correct animation and stop, what i’m doing wrong?