I have an animation that is two frames long. I want it to play for 2 seconds total when the player touches the screen (1 second per frame). Currently, when the player touches the screen the first time, it plays correctly. But any time you touch the screen after the first, the first frame only plays for a few milliseconds, before jumping right to the second frame, not lasting the full 2 seconds for the whole animation. Any ideas what I’m doing wrong here?
Code
require "sprite"
display.setStatusBar( display.HiddenStatusBar )
function HeroBlowEvents( event )
print( "hero frame: " .. ( system.getTimer() - g\_Timer ) )
if ( event.phase == "end" ) then
print( "end frame: " .. ( system.getTimer() - g\_Timer ) )
hero:prepare( "blowright" )
end
end
function HeroTouch( event )
local phase = event.phase
if "began" == phase then
print( "play" )
hero:play()
g\_Timer = system.getTimer()
end
end
function RestartLevel()
Runtime:addEventListener( "touch", HeroTouch )
heroblowrightspritesheet = sprite.newSpriteSheet( "blow-right.png", 188.5, 158 )
heroblowrightspriteset = sprite.newSpriteSet( heroblowrightspritesheet, 1, 2 )
sprite.add( heroblowrightspriteset, "blowright", 1, 2, 2000, 1 )
hero = sprite.newSprite( heroblowrightspriteset )
hero:prepare( "blowright" )
hero:addEventListener( "sprite", HeroBlowEvents )
hero.x = hero.x + 160
hero.y = hero.y + 300
end
RestartLevel()
The results of 3 clicks in this prints the following…
play
hero frame: 1045
hero frame: 2068
end frame: 2068
play
hero frame: 21
hero frame: 1040
end frame: 1040
play
hero frame: 20
hero frame: 1039
end frame: 1039
[import]uid: 17341 topic_id: 11744 reply_id: 311744[/import]
[import]uid: 3826 topic_id: 11744 reply_id: 42756[/import]