In my game I have some box2d bodies where I add sprites using the following code in my render() method.

for (Body body : worldBodies) {
        if (body.getUserData() instanceof Sprite) {
            Sprite sprite = (Sprite) body.getUserData();

            Vector2 position = body.getPosition();
            sprite.setPosition(position.x - sprite.getWidth() / 2 , position.y - sprite.getHeight() / 2);
            sprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);

One of the bodies has to be animated.

birdAnimation = new Animation(1, birdAtlas.getRegions());

This is the animation and now I tried to set the body's sprite obstacle6 to the current textureRegion from the Animation unsing this code:


Somehow it just shows the first texture of the atlas. How can I get it to change? Or is there an other way to animate a box2d body? If you need any other information just comment.


1 Answer 1


Don't pass delta to getKeyFrame, getKeyFrame takes the state time. The state time is likely something like the sum of all the deltas you've seen so far.

The state time indicates how "far" into the animation you've gone, and by constantly passing delta (which if you're running at 60 fps will be 0.016s) the Animation will always yield the first frame.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .