Reputation: 451
I am trying to set my libgdx game to use a certain resolution on all android devices regardless of the devices native resolution.
to be specific my device has a resolution of 720x1280 and I want to use a resolution of 480x800.
On devices where the aspect ratio is different I don't mind how this is resolved.
My current code is
Camera cam = new OrthographicCamera(480,800);
view = new StretchViewport(480, 800, cam);
stage = new Stage();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
but all this seems to do is give me a 480x800 area in the bottom left corner (in which everything renders correctly)! How do I get libgdx to stretch this area to the whole of the devices screen?
Upvotes: 0
Views: 243
Reputation: 19776
Don't set the glViewport
yourself, but let the Viewport
do that for you.
You need the following code snippet in your resize()
method.
public void resize(int width, int height) {
view.update(width, height);
}
Upvotes: 1