3

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?

donfuxx
  • 11,277
  • 6
  • 44
  • 76
user3650664
  • 161
  • 1
  • 14
  • 2
    You need to use mip-mapping if you are scaling textures down. There's an option for `useMipmaps` in the Texture constructor. Also, the texture's filter should be set to (MipMapLinearNearest, Linear) or (MipMapLinearLinear, Linear). The second one looks better on a wider range of devices but performs worse. – Tenfour04 Nov 12 '14 at 18:48

1 Answers1

0

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.

Cristian Gutu
  • 1,221
  • 1
  • 11
  • 24