Sprite based animation plays 1st frame too fast after first play

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]

Just wondering, have you tried calling prepare immediately before the play? [import]uid: 27183 topic_id: 11979 reply_id: 43704[/import]

I have, unfortunately, with the same results. Thank you for asking though. I am definitely still stuck on this one. [import]uid: 17341 topic_id: 11979 reply_id: 43705[/import]

This is kind of a hack, but I have run into issues with the sprites erroring under weird conditions.

What about changing the loop option to loop indefinitely, but stopping the animation after it reaches the end?

[import]uid: 27183 topic_id: 11979 reply_id: 43709[/import]

If you mean change it to loop and then on the “loop” event, setting it to pause, and then playing again when they touch. I’ve done that too, and strangely it’s the same result. :frowning: [import]uid: 17341 topic_id: 11979 reply_id: 43712[/import]

hmm I just ran a test using Spriteloq’s output, and the output looks fine. I am using newSpriteSheetFromData though so I’m not sure if that makes a difference. What build are running?
[import]uid: 27183 topic_id: 11979 reply_id: 43724[/import]

Hmmm…I’d be tempted to try newSpriteSheetFromData if there’s a possibility it’d work. Maybe I’ll start looking into that. Assuming I’m reading things right, I’m running 2011.484. [import]uid: 17341 topic_id: 11979 reply_id: 43725[/import]

ahhh, it’s probably the build then. If you have access to the daily builds a bunch of sprite bugs were fixed. I documented one of them here: http://www.youtube.com/watch?v=2oxO149V8VA I’m guessing there are a bunch of other fixes that were applied, but not explicitly announced.

[import]uid: 27183 topic_id: 11979 reply_id: 43727[/import]

Hehe…after you asked what build I was running, I decided to check if there were newer builds and noticed the daily builds page. Grabbed the latest one(2011.562), and reloaded the original code from above and, unfortunately, same results. Only difference now is the timer value in my prints is a floating point value instead of an integer, like so…

play
hero frame: 1028.914
hero frame: 2051.921
end frame: 2051.921

play
hero frame: 14.812
hero frame: 1033.992
end frame: 1034.037

play
hero frame: 28.69199999981
hero frame: 1047.785
end frame: 1047.823

Thanks again for all your help! Let me know if you have any other ideas. In the meantime I’m going to read about the spritesheetfromdata guy and see if that does anything different for me. [import]uid: 17341 topic_id: 11979 reply_id: 43731[/import]

hmm well I’m stumped, but it looks like things are working in my sample, so I’ve uploaded my project here if you want to check it out: http://loqheart.com/toggle.zip

[import]uid: 27183 topic_id: 11979 reply_id: 43733[/import]

Absolutely! Thx again for all your help! If your project gives me any insights I’ll be sure to add my notes here.

Interesting side note that might help the programmers if one of them notices this thread. The closer to the “end” event to the previous animation that I click, the closer I get to my 1000 milliseconds for the first frame on the next play through. But if I wait any longer than 1000 milliseconds to click after the first play, the first frame only plays for anywhere from 5 to 30 milliseconds(less than one enterframe loop?). It’s almost like the prepare() function just checks to see that it’s on the right starting frame, but doesn’t reset the timer for that frame back to zero.

If anyone else has any ideas, until I’ve had a chance to look at don’s project, I’d love to hear it. Thx in advance. :slight_smile: [import]uid: 17341 topic_id: 11979 reply_id: 43736[/import]

Hi Britt; have you submitted a bug report with steps to reproduce? (You’re able to send your code this way.)

Naturally you should only do that if it’s an issue with the most current build; that’s not to say it needs to be a daily build but .484 isn’t current.

If you let me know, including the bug #, I can try to have someone look at it :slight_smile: (I’m not one of the geniuses on staff, just a minion ;))

Peach [import]uid: 52491 topic_id: 11979 reply_id: 43776[/import]

Hi Peach, I initially wanted to post in the forums just to make sure I wasn’t doing something wrong. But yeah, with no solutions in sight, it’s definitely looking more like a bug. So I’ve entered it into the database and it appears to be #6680. Any help would be greatly appreciated. Thx again! :slight_smile: [import]uid: 17341 topic_id: 11979 reply_id: 43844[/import]

Thank you, I’ll bring it up in our next meeting.

Peach :slight_smile: [import]uid: 52491 topic_id: 11979 reply_id: 43869[/import]

Hey Peach, Hadn’t heard anything back on the bug yet. Any news? [import]uid: 17341 topic_id: 11979 reply_id: 44703[/import]

I don’t personally handle that side of things so I am afraid I’m unable to update you; but I can tell you that it has been brought up.

Sorry I don’t have more info!

Peach [import]uid: 52491 topic_id: 11979 reply_id: 44774[/import]