libgdx Supporting Multiple Resolutions FitViewport

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.

Usage:

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);
}


Got any libgdx Question?