For the complete documentation index, see llms.txt. This page is also available as Markdown.

UI Fundamentals

Adding UI to your game requires writing code, but with the help of AI it's substantially easier to make sophisticated interactive UIs


Adding UI to your game requires writing code, but once you learn a few patterns you can build clean, scalable interfaces quickly. This guide walks you through a step-by-step tutorial that ends with a complete dialog example.

All UI for a player must be drawn inside that player's ao_late_update call stack and wrapped with is_local_or_server(). This prevents UI from appearing for the wrong client. Do not draw player UI from global or non-player component callbacks.

At any time, you can jump to UI Reference for more patterns and deeper details.

Step 1: Create a UI Entry Point

All interactive UI should be drawn from the local player's ao_late_update:

Player :: class : Player_Base {
    ao_late_update :: method(dt: float) {
        if this.is_local_or_server() {
            draw_ui(this);
        }
    }
}

Step 2: Start From a Screen Rect

Screen UI should always be derived from UI.get_safe_screen_rect() or UI.get_screen_rect(). Remember: (0, 0) is the bottom-left and Y grows upward.

Screen-space sizes passed to the regular rect helpers are points on a 1080-point-tall reference canvas. The engine scales those points to the device's actual pixels, so the same layout keeps a consistent relative size across resolutions.

draw_ui :: proc(player: Player) {
    screen := UI.get_safe_screen_rect();

    // A simple centered panel
    panel := screen.center_rect().grow(120, 200, 120, 200);
    UI.quad(panel, core_globals.white_sprite, {0, 0, 0, 0.7});
}

Step 3: Use Cut For Layout

When laying out multiple elements, cut space out of a rect instead of positioning everything from the same origin.

Step 4: Add Text

Use text settings to control size, color, and alignment.

Step 5: Add Buttons

Buttons combine layout and interaction. Use a button sprite from the engine supplied assets (see UI Reference for more).

Step 6: Build a Dialog

Now combine all of the steps into a reusable dialog layout.

Last updated