libgdx Supporting Multiple Resolutions StretchViewport


Example

The StretchViewport is a Viewporttype, which supports a virtual screen size.
This allowes you to define a fixed (resolution independent) width and height.
The StretchViewport, as the name suggests, stretches the virtual screen, if the virtual aspect ratio does not match the real aspect ratio. The OpenGL Viewport won't be modified and there won't appear black bars.

Usage:

private Viewport viewport;
private Camera camera;

public void create() {
    camera = new OrthographicCamera();
    viewport = new StretchViewport(80, 48, camera);
}

public void resize(int width, int height) {
    viewport.update(width, height);
}