-
Notifications
You must be signed in to change notification settings - Fork 40
Viewports
Giacomo Tommaso Petrucci edited this page Sep 16, 2022
·
3 revisions
For managing how your game will look in different screens and screen sizes it is easiest to use a Viewport.
Viewports in Mini2Dx are very simple to use.
FitViewport
//Constructing the viewport
FitViewport fitViewport;
float gameWidth = 800;
float gameHeight = 600;
@Override
public void initialize() {
fitViewport = new FitViewport(gameWidth, gameHeight);
}
//Inside the render() method
@Override
public void render(Graphics g) {
fitViewport.apply(g);
//do your rendering inside the viewport
}Now when you run with this viewport your world aspect ratio will be fit to the 800x600 viewport size. When you resize the window, it will grow to fit the screen, but by maintaining the aspect ratio will apply black borders to the edges.
For more examples of how the viewports each look see LibGDx Viewports
Getting Started
Graphics
Gameplay
Data
- Asset Management
- Saving and loading player data
- Converting objects to/from JSON
- Converting objects to/from XML
User Interfaces / HUDs
Structuring your code
Releasing your game