1

I am using 480*800 image for my libgdx game. It is running absolutely fine on my smartphone but when i try to run it on high end devices or say tab with resolution 800*1280, it just show the image at one corner of the screen for obvious reasons.

I am sure it just needs some camera settings to scale up and down according to the different screen resolutions. Please help me or provide any pointer.

IamHunt
  • 21
  • 1
  • 1
  • 3

3 Answers3

4

You can use ViewPort as maintained above or use your own solution, like this:

    public static float SCALE_RATIO = YOUR_IMAGE_WIDTH / Gdx.graphics.getWidth();

    public static Sprite createScaledSprite(Texture texture) {
       Sprite sprite = new Sprite(texture);
       sprite.getTexture().setFilter(TextureFilter.Linear,
                TextureFilter.Linear);
       sprite.setSize(sprite.getWidth() / SCALE_RATIO,
            sprite.getHeight() / SCALE_RATIO);
       return sprite;
    }
Alon Zilberman
  • 2,120
  • 1
  • 16
  • 16
0

You can use viewports. https://github.com/libgdx/libgdx/wiki/Viewports

This way to are programming for a fixed resolution, programming to a relative resolution can be tricky.

Boldijar Paul
  • 5,405
  • 9
  • 46
  • 94
0

You can always access the width and height of the camera you are using. In your screen you should have a resize method which you can use to resize the viewport of the camera or so. Then you can scale towards the camera size.

Nine Magics
  • 444
  • 4
  • 3