Skip to content
Download

HUD and pause menu

  1. In Resources, + › New interface…, named Hud.
  2. Add a Text named Moedas and a Bar named Vida.
  3. In the room Inspector, check Hud under 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)
end
  1. Create the Pausa interface: a Panel with the Buttons Continuar, Recomecar and Sair.
  2. To darken the game behind it, add at the end of the list a screen-sized Panel, black with transparency.
  3. 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")
end
end
function onPausedUpdate(self)
if pressed("pausar") then
setPaused(false)
Ui.hide("Pausa")
end
end
  • While paused, instances receive onPausedUpdate instead of onUpdate. Drawing and the interface keep running.
  • Buttons respond to mouse, keyboard and gamepad (actions cima, baixo, esquerda, direita and confirmar).
  • 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.

Reference: Interface. Editor: Interface.