libgdx Supporting Multiple Resolutions FitViewport


FitViewports are viewports that always maintain the aspect ratio. It does this by creating black bars on the edges where there is space left. This is one of the most commonly used viewports.


private Viewport viewport;
private Camera camera;

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

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