Search code examples
libgdx

How do I scale a Libgdx Animation?


I an currently using Libgdx Animation class( com.badlogic.gdx.graphics.g2d.Animation) in a game. However I need the animation to grow in size on certain events. How do I accomplish this?


Solution

  • Animation is used to select the correct frame (TextureRegion) based on the time elapsed. It has nothing to do with how you render that frame. Therefor it is not different as how you render anything else.

    You didn't provide enough information for that. But usually you'd render it something like this:

    TextureRegion textureRegion = animation.getKeyFrame(time += delta);
    spritebatch.draw(textureRegion, x, y, width, height);
    

    So to change the size would be to change the width and height variables. You didn't provide enough information on how you'd like to do that. But you can do that for example using this:

    width = 0.8f;
    height = 1.9f;