Coordinate system
When you draw shapes or textures in your game, you are working with a coordinate system. Understanding coordinates is essential to place objects where you want them and make them scale correctly on different screens.
Origin and axes
In the Saxion Game App, the origin of the coordinate system — the point (0, 0) — is located at the bottom-left corner of the screen by default.
- The X-axis increases to the right.
- The Y-axis increases upward.
- Every position (x, y) represents a point measured from the bottom-left corner.
Why bottom-left?
If you’ve worked with image editing tools, web pages or the SaxionApp before, you might be used to coordinates starting at the top-left corner (as in HTML, CSS, or many 2D GUI systems). However, LibGDX follows the mathematical convention used in Cartesian coordinate systems, where:
- The origin is at the bottom-left.
- The Y-axis increases upward.
This convention makes sense for games and graphics programming because:
- It matches how we plot graphs in math (increasing upward).
- It works naturally with world coordinates in 3D and 2D physics simulations.
- It’s consistent across rendering systems like OpenGL, which LibGDX is built on.
World coordinates
Imagine you are creating a game, and your characters live in a tiny game world. In this world, you want your player to always be able to move from left to right, jump, and interact with objects — regardless of the size of the player’s screen. This is where world coordinates come in.
Window vs World coordinates
The window (the screen) is the picture frame in which your application gets rendered. Its size can change. For example, because the resolutions of your users are different:
- On a laptop it might be 800×600 pixels.
- On a tablet, it might be 1920×1080 pixels.
We want to develop games that scale well. Calculating everyting based on the window size of a user is going to be very difficult. Therefore we are going to determine our own world coordinates. They represent a fixed game world inside the frame. The window just looks at a portion of this world and scales it to fit.
The default strategy here is, that the game keeps it's aspect ratio. The window might show you black bars on the top and bottom or left and right, if the windows size has a different aspect radio than the game.
The image below shows you what the window might look like when the world and the window have different aspect ratio.
💡 Tip: choose a virtual world size that makes sense for your game.
For example:Keep your coordinate system consistent across all screens — this ensures smooth scaling and positioning on different devices.
- 800×480 for games in landscape orientation
- 480×800 for games in portrait orientation
- 1024×576 for 16:9 aspect ratio games.
Below you will see a minimal example of create a screen for you application with a world size of 800 x 480. You can think of these 800 x 480 in any logical metric that you like (pixel, meters, cm), whatever is suitable for you.
public class MyScreen extends ScalableGameScreen {
public MyScreen() {
super(800, 480); // world size
}
@Override
public void render(float delta) {
// IMPORTANT: this will make sure world coordinates and the window coordinates are in sync.
super.render(delta);
// 1. Get user input
...
// 2. Update location of elements
...
// 3. Game logic
...
// 4. Drawing
GameApp.clearScreen("skyBlue");
}
}
We can get information about the world by using the getWorldWidth() and getWorldHeight() methods. The screens article explains these methods in more detail.