Coding Academy home

Help & Lessons / Messages, Buttons & Restarting

Messages, Buttons & Restarting

Showing a Message

UI.showMessage(text, color) shows a big message over the whole game — perfect for "Game Over," "You Win!," or anything that needs the player's full attention.

export function update(self) {
    if (self.health <= 0) {
        UI.showMessage("Game Over!", "red");
    }
}

The color is optional — leave it out and it's plain white text.

The moment showMessage() is called, every shape's update() stops running — the whole game visibly freezes right where it was, behind the message. Nothing moves, nothing scores, nothing checks for touches, until the message is hidden again.

Hide it with UI.hideMessage(), which un-freezes everything exactly where it left off:

UI.hideMessage();

You don't have to call these from the shape that's showing them — UI.showMessage(...) works from any shape's code, the same way Game.getShape(...) does.

Wondering why a shape's own code doesn't run again once showMessage() freezes the game — including the if (self.health <= 0) check that showed it in the first place? That's expected: nothing runs while frozen. Something else, like a button (see the next lesson), needs to be what un-freezes it.