Rooms
| Function | What it does | Example |
|---|---|---|
void goTo(std::string_view name) |
Switches to the room with that name, at the end of the frame. | goTo("Level2"); |
void restart() |
Recreates the current room from scratch, at the end of the frame. Several calls on the same step count as one. | if (pressed(Key::R)) restart(); |
int roomWidth() const |
Width of the current room, in pixels. | if (x > roomWidth()) x = 0; |
int roomHeight() const |
Height of the current room, in pixels. | if (y > roomHeight()) destroy(); |
void brasa::quit() |
Closes the game at the end of the frame. It is a free function: with using namespace brasa; in the file, quit() is enough. |
if (pressed(Key::Escape)) brasa::quit(); |
void brasa::fadeTo(std::string_view room, float seconds = 0.6f, Color color = colors::black) |
Changes room with a fade: the screen goes to the color, the room changes and the screen comes back. | fadeTo("Fase2"); |
void brasa::flash(Color color = colors::white, float seconds = 0.2f) |
Covers the screen with a color that fades in seconds seconds (a flash, the red of taking damage). |
flash(Color{255, 0, 0, 120}, 0.3f); |
Outside an object
Section titled “Outside an object”goTo only exists inside an object. In a free function (for example, in game.cpp), use brasa::goToScene("Name"), which does the same:
void newGame() { state() = GameState{}; brasa::goToScene("Main");}- When you switch rooms, all the instances of the current room are destroyed and the ones of the new room start with
onSpawn. - A room name that doesn’t exist is reported in the Saída (Output) and ignored.
- The first room of the game is the start room, set in Project settings.
