Drawing
Each instance draws its own sprite. To draw something else, use these functions inside onRender (in the world, with camera) or onRenderGui (on screen, on top of everything).
| Function | What it does |
|---|---|
drawSelf() |
Draws the instance sprite, with its scale, angle and position. |
drawSprite(sprite, frame, x, y) |
Draws a sprite at a position. Optional: X scale, Y scale, angle and alpha (0 to 1). |
drawRect(x, y, width, height, color) |
Draws a rectangle. A last argument false draws only the outline. |
drawLine(x1, y1, x2, y2, color) |
Draws a line. |
drawText(text, x, y, color) |
Writes with the built-in font (8-pixel letters). A fifth argument scales it: 2 = 16 pixels. |
drawText(text, x, y, color, font, size) |
Writes with a project font (.ttf), at the given size in pixels. |
function onRender(self) self:drawSelf() drawRect(self.x - 8, self.y - 14, 16 * self.vida, 2, colors.red)end
function onRenderGui(self) drawText("Pontos: " .. self.pontos, 4, 4, colors.white)endvoid onRender() override { drawSelf(); drawRect(x - 8, y - 14, 16 * vida, 2, colors::red);}
void onRenderGui() override { drawText(std::format("Pontos: {}", pontos), 4, 4, colors::white);}Colors
Section titled “Colors”A color has r, g, b and a (opacity), from 0 to 255. Ready-made: white, black, red, green, yellow and magenta.
local laranja = Color(255, 90, 31)local sombra = Color(0, 0, 0, 128)drawRect(0, 0, 320, 180, sombra)const Color laranja{255, 90, 31, 255};const Color sombra{0, 0, 0, 128};drawRect(0, 0, 320, 180, sombra);