Tried sending an email to support@ and posted in the Game Development forum and have had no response. I really need to solve this issue and since no one is telling me my code is wrong, I have to assume it’s a bug. Please help. I need to get this sorted out.
I have an animation that is two frames long (I’ve tried 3 frames and get the same results). 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 (not the 1000 milliseconds I’ve told it to), before jumping right to the second frame (which *does* play for its full 1000 milliseconds fine), not lasting the full 2 seconds for the whole animation. Any ideas what’s going on here?
Code
require "sprite"
display.setStatusBar( display.HiddenStatusBar )
function HeroGoEvents( event )
print( "hero frame: " .. ( system.getTimer() - g\_Timer ) )
if ( event.phase == "end" ) then
print( "end frame: " .. ( system.getTimer() - g\_Timer ) )
hero:prepare( "goright" )
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 )
herogorightspritesheet = sprite.newSpriteSheet( "go-right.png", 188.5, 158 )
herogorightspriteset = sprite.newSpriteSet( herogorightspritesheet, 1, 2 )
sprite.add( herogorightspriteset, "goright", 1, 2, 2000, 1 )
hero = sprite.newSprite( herogorightspriteset )
hero:prepare( "goright" )
hero:addEventListener( "sprite", HeroGoEvents )
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
Additional notes:
I’ve tried making a 3-frame animation. Same results (in that the 1st frame plays short every time after the first play, while all following frames play for their full length).
I’ve tried using the 3-frame spritesheet to say that the 2-frame animation is the 2nd and 3rd frames. Same result.
I’ve tried setting the spriteset to loop(0) instead of play once(1) and changed the spriteevent function to check for “loop” with the same code as the “end” above. Same result.
I’ve tried manually changing the .currentFrame to 1, 2, or 3 before and after the prepare(), same result.
The only thing left I can think to do is kill and recreate the entire spritesheet, spriteset, and sprite every time I loop, but that seems hacky. Any ideas?
[import]uid: 17341 topic_id: 11979 reply_id: 311979[/import]