Drawing
By default, each instance draws its own sprite. To draw other things, override onRender (in the world, with the camera) or onRenderGui (on top of everything, in screen coordinates) and use the functions below inside those events.
| Function | What it does | Example |
|---|---|---|
void drawSelf() |
Draws the instance’s own sprite at the current frame, with the scale, angle and position of the instance. | drawSelf(); |
void drawSprite(std::string_view spriteName, float frameIndex, float atX, float atY, float sx = 1, float sy = 1, float rotation = 0, float alpha = 1) |
Draws any sprite, at any position. alpha goes from 0 (invisible) to 1. |
drawSprite("coracao", 0, 4, 24); |
void drawRect(float rx, float ry, float rw, float rh, Color color, bool filled = true) |
Draws a filled rectangle or only the outline. | drawRect(4, 30, 50, 4, colors::red); |
void drawLine(float x1, float y1, float x2, float y2, Color color) |
Draws a line. | drawLine(x, y, mouseX(), mouseY(), colors::white); |
void drawText(std::string_view text, float tx, float ty, Color color = colors::white) |
Writes a text, with accents. Each letter is 8 pixels wide. | drawText("Pausa", 140, 80); |
void drawText(std::string_view text, float tx, float ty, Color color, int scale) |
The same, scaled up: scale 2 gives 16-pixel letters. |
drawText("Pausa", 120, 80, colors::white, 2); |
void drawText(std::string_view text, float tx, float ty, Color color, std::string_view font, int size) |
Writes with a project font (a .ttf imported in Resources), with letters size pixels tall. |
drawText("Fim", 120, 80, colors::white, "Titulos", 24); |
For menus, scores and screens, see the Interface: texts are placed in the editor and the code only changes what they show.
Colors
Section titled “Colors”Color{r, g, b, a} with values from 0 to 255 (a is the opacity). Ready-made colors in colors:::
| Name | Value |
|---|---|
colors::white |
{255, 255, 255, 255} |
colors::black |
{0, 0, 0, 255} |
colors::red |
{230, 60, 60, 255} |
colors::green |
{60, 220, 90, 255} |
colors::yellow |
{255, 220, 60, 255} |
colors::magenta |
{255, 0, 255, 255} |
Drawing order
Section titled “Drawing order”- The layer decides the order: the one at the top of the list is drawn in front. Each layer has a
depth, and the higher one goes behind. - An instance is created with the depth of its layer. In the code,
setLayer("Frente")moves it to another layer;depth = 5;works too. - Everything drawn in
onRenderGuistays on top of everything fromonRender. - An instance with
visible = falsedraws nothing.
See Text on screen and Animate a sprite.
