Short question about the scaling in libGDX. At the moment i have a application with the resolution 480x320. I define this in the main method of the desktop launcher. My whole application is now calculating with this resolution. For example is the player 50x50 pixels. How can i now scale my application to, for example, 1920x1080 on android so my player is now not only 50x50? I use a orthographic camera and give the width and height of 480x320 in the constructor.
Take a look as using a different type of ViewPort (this page shows the different types).
Based on what you have described I would recommend using a StretchViewport, which would upscale (or downscale) your 480x320 camera to whatever resolution you needed it to be.
Note that if you changed the aspect ratio you might get some ugly stretching artefacts.
On the resize event method in your
ApplicationListener (the main game class) change public static width and height integers like so:
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
float scale = (float)prefferedWidth / (float)WIDTH;
WIDTH = (int) (WIDTH * scale);
HEIGHT = (int) (HEIGHT * scale);
prefferedWidth is the in-game-world width that you want to cover. This keeps the aspect ratio from being gross and stretchy on different phones. Then you just use this
HEIGHT to set up your camera:
//gsm.game is how I obtain the instance of the main game class
cam = new OrthographicCamera(GdxGame.WIDTH,GdxGame.HEIGHT);
It keeps the window nice and pretty without skewing. If you make a portrait game do the scaling based on your
prefferedHeight / HEIGHT