HUD y menú de pausa
- En Recursos, + › Nova interface…, con el nombre
Hud. - Pon un Texto llamado
Moedasy una Barra llamadaVida. - En el Inspector de la room, marca
Huden Interfaces: se abre junto con la 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);}Menú de pausa
Sección titulada «Menú de pausa»- Crea la interfaz
Pausa: un Painel con los BotõesContinuar,RecomecarySair. - Para oscurecer el juego detrás, pon al final de la lista un Panel del tamaño de la pantalla, negro con transparencia.
- En Configuración del proyecto, crea la acción
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"); }}- En pausa, las instancias reciben
onPausedUpdateen lugar deonUpdate. El dibujo y la interfaz continúan. - Los botones responden al mouse, al teclado y al mando (acciones
cima,baixo,esquerda,direitayconfirmar). - El panel oscuro retiene el clic: con la pausa abierta, hacer clic no llega al juego.
- Las plantillas Plataforma y Zumbis tienen HUD, pausa y pantalla final listos.
