How to display image size proportional to libgdx?

1

How do I display the images in my game that are size proportional to the screen size of the device, so that if an image has a 1/3 width of the screen on a 480x800 screen, it should also have the same 1/3 320x480 or 720x1280? I think it's with ' camera.setToOrtho() ', does anyone know how to do it?

    
asked by anonymous 12.06.2016 / 01:03

1 answer

1

Well, I've worked very little on libgdx, but from what I've seen, you can use Viewports to resize your image .But I confess I have never tested this way.

Another solution, which I have already seen being implemented is to create your own function to resize your Sprite, for example:

 public static float MINHA_PROPORCAO = WIDTH_IMAGEM / Gdx.graphics.getWidth(); // Calcula uma proporção baseada no tamanho da tela.

  public static Sprite CriarSprite(Texture textura) {

   Sprite sprite = new Sprite(textura);
   sprite.getTexture().setFilter(TextureFilter.Linear,TextureFilter.Linear);
   sprite.setSize(sprite.getWidth() / MINHA_PROPORCAO ,
   sprite.getHeight() / MINHA_PROPORCAO );
   return sprite;
  }

I hope it helps :)

    
05.07.2016 / 21:44