Text on screen
You want to show the scoreboard, the lives or a message that always stays in the same place on screen.
Create an object without a sprite (for example Hud), place it in the room and draw in onRenderGui:
#include <brasa/brasa.hpp>#include <format>using namespace brasa;
class Hud : public Entity {public: void onRenderGui() override { drawText("PRIMEIRA FASE", 4, 4); drawText(std::format("PONTOS {}", 1500), 4, 14, colors::yellow); }};BRASA_ENTITY(Hud);How it works
Section titled “How it works”onRenderGuidraws on top of everything, in screen coordinates: (0, 0) is the top left corner, even with the camera moving.drawText(text, x, y)writes the text. The color is optional:colors::white(default),colors::yellow,colors::red,colors::green,colors::blackorColor{r, g, b, a}.std::formatbuilds texts with numbers:std::format("VIDAS {}", 3)becomesVIDAS 3.- Each letter is 8 pixels wide. Accents and cedillas work:
drawText("Pontuação", 4, 4).
Variations
Section titled “Variations”Center. The text takes up letters × 8 pixels:
const std::string msg = "FIM DE JOGO";drawText(msg, (roomWidth() - msg.size() * 8.0f) / 2.0f, 80);Bigger letters and another font. A number after the color scales up Brasa’s font (2 = 16-pixel letters). With the name of a font imported in Resources and the size in pixels, the text uses that font:
drawText("Pontuação", 4, 4, colors::white, 2);drawText("Fim de jogo", 4, 30, colors::yellow, "Titulos", 24);Numbers with leading zeros: std::format("{:05}", 300) becomes 00300.
Rectangles and lines, for health bars and frames:
drawRect(4, 30, 50, 4, colors::red); // filled bardrawRect(4, 30, 50, 4, colors::white, false); // outline onlySee also
Section titled “See also”- Drawing.
- 5. Score and lives, in the tutorial.
