Reducing texture quality libGDX

I am new to libGDX and I just wanted to put an image on the screen. I have a red ball image that is 800x800 and when I try to paint a texture:

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

      

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

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

enter image description here

Any help on how to make the images clearer and smoother?

+3


source to share


1 answer


From what I know, you have two options.

One option is to have FitViewport and keep the screen the same size at all times, which will ultimately preserve the quality of your images. In this case, the class FitViewport

will 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 proportional to the given screen.

Overall, while these approaches may seem a little tedious, they are indeed the best way to maintain "crisp and smooth" images across different screen sizes.

Keep in mind that by resizing an image, you actually reduce the number of pixels in pixels. Therefore, when you try to resize the image, some pixels are "lost" and the original texture cannot be reproduced, resulting in a loss of clarity.

0


source







All Articles