First UI Scene¶
This tutorial builds a UI scene — a separate scene dedicated to screen-space widgets — and shows how to layer it on top of a gameplay scene. UI scenes are the recommended approach for HUDs, menus, and overlays in Doriax.

What you will build¶
By the end of this tutorial you will have:
- A UI scene with a centered panel, a text label, and a Button
- A
Progressbaracting as a health bar in the top-left corner - The UI scene loaded on top of a gameplay scene
- A script that updates the health bar value from gameplay logic
1. Create a UI scene¶
- Open the editor and open or create a project that already has a gameplay scene
(
mainorlevel_01). - Choose File → New Scene and select the UI template.
- Save it as
scenes/hud.scene.
The UI template sets up an orthographic camera and a canvas root entity.
2. Set the canvas size¶
Select the scene root and set the Canvas Size to your design resolution —
for example 1920 × 1080. Set Scaling Mode to LETTERBOX to maintain aspect ratio
across different screen sizes.
3. Add a health bar¶
- In the Structure panel, right-click the canvas root and choose Create → Progressbar.
- In the Properties window:
- Set Anchor Preset to
TOP_LEFT. - Set Width to
300and Height to24. - Set the Margin Left and Margin Top to
20each (inset from the edge). - Set Min Value to
0and Max Value to100. - Set the initial Value to
80. - Assign a fill texture or set a fill Color (e.g. green for health).
- The health bar appears in the top-left corner of the canvas.
4. Add a center panel with a button¶
For a "Game Over" overlay:
- Right-click the canvas root → Create → Panel.
- Set Anchor Preset to
CENTERand Size to400 × 250. - Assign a background texture to the panel, or leave it as a solid color.
Add a label inside the panel:
- Right-click the panel → Create → Text.
- Set Anchor Preset to
TOP_WIDE. - Set the Text to
"Game Over"and Font Size to40.
Add a restart button:
- Right-click the panel → Create → Button.
- Set Anchor Preset to
BOTTOM_CENTER. - Set the Label text to
"Restart". - In the Properties window, set the On Press callback to a Lua script function (see the next step).
5. Write a HUD script¶
Create a Lua script scripts/HUD.lua:
local HUD = {}
HUD.__index = HUD
DPROPERTY("Health Bar Entity")
HUD.healthBarEntity = nil
function HUD:init()
RegisterEngineEvent(self, "onUpdate")
end
function HUD:onUpdate()
-- Read health from a shared value or an event
-- For demonstration, use a global updated by gameplay code
if GameState and GameState.health and HUD.healthBarEntity then
local bar = Progressbar(self.scene, self.healthBarEntity)
bar.value = GameState.health
end
end
return HUD
Attach the script to the canvas root entity via ScriptComponent, and use the
DPROPERTY entity reference field to link the health bar entity.
6. Load the UI scene as a layer¶
In the project's startup file or main scene script, add the HUD scene as a layer:
The UI scene renders on top of the gameplay scene automatically.
7. Run and test¶
Press Play. You should see:
- The gameplay scene rendering as normal.
- The health bar in the top-left corner.
- The "Game Over" panel centered on screen.
- The "Restart" button responding to clicks.
If the UI is not visible:
- The HUD scene is registered and loaded as an additive layer with
addSceneLayer, notsetScene. - The canvas size and scaling mode are set correctly.
- The UI scene camera is orthographic.
- UI events are enabled on the scene (
scene.uiEventsEnabled = true).
8. Next steps¶
- Add a pause menu to a separate UI scene and toggle it with Escape.
- Use
ContainerwithVERTICALlayout for a dynamic item list. - Use
TextEditfor a name-entry field in a high-score screen. - Continue with User Interface for the full UI system reference.