Skip to content
Download

Switch rooms

You want to go to another level, show a Game Over screen or start over.

// hp is a variable of your object, for example: int hp = 3;
if (hp <= 0) goTo("GameOver");
  • goTo("Name") switches to the room with that name at the end of the current frame. The rest of the step finishes normally.
  • When you switch rooms, all the instances of the current room disappear and the ones of the new room start from scratch, with onSpawn.
  • The first room of the game is the start room, marked as (inicial) in Recursos (Resources). You change it in Projeto › Configurações do projeto… › Room inicial (Project › Project settings › Start room).

Restart the current room:

if (pressed(Key::R)) restart();

Close the game:

if (pressed(Key::Escape)) quit();

Keep data between rooms. The instances disappear on the switch, so score and lives need to live outside them, in a shared state. The tutorial shows how in 5. Score and lives.

Size of the room. roomWidth() and roomHeight() give the size of the current room, in pixels.