location-dotWorld Space UI

Use world space UI to draw text above players heads and any other text that should feel like it's part of the game world itself.

World space UI is drawn in the 2D world instead of on the screen. Use it for nameplates, health bars, signs, and any text that should feel anchored to game objects.

circle-info

World space UI uses meters for sizing. If you use screen-style pixel sizes, your UI will be enormous.

Core Rules

  • Always call UI.push_world_draw_context() and defer UI.pop_draw_context().

  • Use meters for rect sizes and offsets.

  • Push Z for proper depth sorting (commonly use pos.y).

  • Use subrect only for percentage fills (like health bars).

Examples

Displaying a player's level

draw_player_level :: proc(player: Player) {
    UI.push_world_draw_context();
    defer UI.pop_draw_context();

    pos := player.world_position;
    UI.push_z(pos.y);
    defer UI.pop_z();

    ts := UI.default_text_settings();
    ts.size = 0.30; // World space text size
    ts.halign = .CENTER;
    ts.valign = .CENTER;

    text_pos := pos + v2{0, 1.7};
    rect := Rect{text_pos, text_pos}->grow(0.05, 0.4, 0.05, 0.4);
    UI.text(rect, ts, "Lvl %", {player.level});
}

Player base signs

Health bars

Coordinate Conversion

Tips

  • Keep world UI minimal and readable at distance. If you have a zoomable camera, make sure to adjust text size when you zoom out.

  • Use fit_aspect() if you draw icons in world space.

  • If text flickers or overlaps, check your Z values and spacing.

Last updated