Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having a small issue with libgdx animation.

I'm using getKeyFrame() to get the current frame of the animation and I'm updating the state time by adding on deltaTime in my update function for the object. The animation is not looping.

My problem is that the animation seems to play at different speeds depending on the frame rate. On my phone this animation plays particularly slow. My thinking was that the stateTime would cause it to skip a few frames when it's going slow, but this doesn't seem to be happening.

Here is the code;

        sprite = Animation.getKeyFrame(stateTime, false);
        sprite.setRotation(angle);
        sprite.setPosition(position.x, position.y);
        sprite.draw(batch);

Has anyone else experience this issue.

share|improve this question
    
Maybe your delta time is wrong? –  Laurent Couvidou Apr 27 '12 at 19:01
    
The delta time seems fine. I tried doing stateTime * 100000 and that made no difference and I have changed the animation time with no difference. –  OriginalDaemon Apr 28 '12 at 1:20
    
Maybe a bug in libgdx, then... –  Laurent Couvidou Apr 29 '12 at 15:55
    
I'm hoping to spend some more time this week trying to find out if that's the case. I was just hoping that someone else had run into it at some point. –  OriginalDaemon Apr 29 '12 at 18:10
    
Based om depresscreate's answer, you may just need to upgrade to 0.9.3 –  ashes999 May 1 '12 at 21:18

2 Answers 2

up vote 1 down vote accepted

I;ve tested it and it seems to work ok on libgdx 0.9.3... Can it be some problem with the way you generate "stateTime"? I would also look in the frameDuration argument that the Animation constructor get.

share|improve this answer
    
The frame duration is 0.66f I think. But I don't think it's that because I would still expect the animation to play at the same rate on all devices. I'll try upgrading to 0.9.3. I thought I had done that, but it was very late so I'll try again. –  OriginalDaemon May 1 '12 at 22:35
    
I updated to 0.9.3 and everything seems to be working. So I think I had an old version of the library, but I did do a bit of cleaning up of the code as well, so I can't say that definitively. –  OriginalDaemon May 2 '12 at 22:52

Check this: getKeyFrame

sprite = Animation.getKeyFrame(stateTime, true);

Animation seems to play at different speeds depending on the frame rate. Can you verify if your game runs at 60fps or 30fps? I also recommend you look for information about "frame skip".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.