AleksandarAngelov
AleksandarAngelov

Reputation: 90

How to scale the Sprite in libgdx?

I have an image which is 100x100 size. I want to use the whole image but with size of 50x50. When I try to use it, it crops my image and uses only 1/4 of the image (top - left corner).

Texture img = new Texture("snake.png");
Sprite mySnake = new Sprite(img);

I have tried using mySnake.setSize(50,50) but it doesn't do anything.

Upvotes: 4

Views: 8880

Answers (1)

Ashlesha Sharma
Ashlesha Sharma

Reputation: 949

You can scale sprite like:

  1. Set the Actor's scale: sprite.setScale(factor);

  2. With animation: Use Tween engine (LibGDX animation library)

  3. Use a custom width in your SpriteBatch call: batch.draw(Sprite, float x, float y, float width, float height);

Upvotes: 2

Related Questions