简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM