HUD and pause menu
- In Resources, + › New interface…, named
Hud. - Add a Text named
Moedasand a Bar namedVida. - In the room Inspector, check
Hudunder Interfaces: it opens together with the room.
function onUpdate(self) local hud = Ui.get("Hud") hud["Moedas"]:setText("Moedas: " .. self.moedas) hud["Vida"]:setValue(self.vida / 100)endvoid onUpdate() override { Ui::Element hud = Ui::get("Hud"); hud["Moedas"].setText(std::format("Moedas: {}", moedas)); hud["Vida"].setValue(vida / 100.0f);}Pause menu
Section titled “Pause menu”- Create the
Pausainterface: a Panel with the ButtonsContinuar,RecomecarandSair. - To darken the game behind it, add at the end of the list a screen-sized Panel, black with transparency.
- In Project settings, create the action
pausar.
function onSpawn(self) local pausa = Ui.get("Pausa") pausa:hide() pausa["Continuar"]:onClick(self, function() setPaused(false) Ui.hide("Pausa") end) pausa["Recomecar"]:onClick(self, function() restart() end) pausa["Sair"]:onClick(self, function() quit() end)end
function onUpdate(self) if pressed("pausar") then setPaused(true) Ui.show("Pausa") endend
function onPausedUpdate(self) if pressed("pausar") then setPaused(false) Ui.hide("Pausa") endendvoid onSpawn() override { Ui::Element pausa = Ui::get("Pausa"); pausa.hide(); pausa["Continuar"].onClick(this, [] { setPaused(false); Ui::hide("Pausa"); }); pausa["Recomecar"].onClick(this, [this] { restart(); }); pausa["Sair"].onClick(this, [] { quit(); });}
void onUpdate() override { if (pressed("pausar")) { setPaused(true); Ui::show("Pausa"); }}
void onPausedUpdate() override { if (pressed("pausar")) { setPaused(false); Ui::hide("Pausa"); }}- While paused, instances receive
onPausedUpdateinstead ofonUpdate. Drawing and the interface keep running. - Buttons respond to mouse, keyboard and gamepad (actions
cima,baixo,esquerda,direitaandconfirmar). - The dark panel captures the click: with the pause open, clicks do not reach the game.
- The Platformer and Zombies templates have a ready HUD, pause and end screen.
