libGDX texture quality scaling down

1.3k views Asked by At

i am new to libGDX and I just wanted to put a image onto the screen. I have a red ball image which is 800x800 and when i try draw the texture:

batch.draw(ball,50,50,50,50);

The quality of the ball is really bad, but when I don't scale it down, the quality is good.

Here is a image on what I see on the screen:http://prntscr.com/55oars

enter image description here

Any help on how to make the images more crisp and smoother?

1

There are 1 answers

0
Cristian Gutu On

From what I know you have two options.

One option is to have a FitViewport and constantly maintain your screen to be the same size which would ultimately preserve the quality of your images. In this case the FitViewport class would help you do this by adding black bars on the screen to take care of the extra space. Example:

private Viewport viewport;
private Camera camera;

public void create() {
    camera = new PerspectiveCamera();
    viewport = new FitViewport(800, 480, camera);
}

public void resize(int width, int height) {
    viewport.update(width, height);
}

Another option is to have a TexturePacker and load images that are proportional for a given screen.

All in all while these approaches may seem a bit tedious they really are a better way to maintain "crisp and smooth" pictures throughout different screen sizes.

It is worth remembering that by resizing the image, you actually reduce the pixel count of the photo. Therefore when you try to resize the image some pixels are "lost" and the original texture cannot be reproduced hence loss of clarity.