Drawing
Scripts draw on the screen with draw, in a render2d handler, and in the world with draw3d, in a render3d handler. Both run every frame, so draw everything again each time. See Values for how colours are written.
The render2d handler gets the draw table as its argument, so ctx.text(...) and draw.text(...) are the same.
events.on("render2d", function(ctx) local w = ctx.screen() ctx.rect(w / 2 - 60, 8, 120, 26, 0xB0101114, 6) local fps = string.format("%.0f fps", client.fps()) ctx.text(fps, w / 2, 12, 0xC8F135, 16, { align = "center" })end)| Function | What it does |
|---|---|
draw.text(text, x, y, colour, size, options) |
Draws text. colour is white and size 18 unless you say (4 to 200). options is a table: align ("left", "center" or "right" of x), shadow (on unless false) and font. Returns the text’s width and height. |
draw.textWidth(text, size, font) |
Returns the width and height text would take, without drawing it. |
draw.rect(x, y, w, h, colour, rounding) |
Draws a filled rectangle, with rounded corners when you give a rounding. |
draw.outline(x, y, w, h, colour, thickness, rounding) |
Draws a rectangle’s outline, 1 pixel thick unless you say. |
draw.line(x1, y1, x2, y2, colour, thickness) |
Draws a line, 1 pixel thick unless you say. |
draw.circle(x, y, radius, colour, thickness) |
Draws a filled circle, or its outline when you give a thickness. |
draw.triangle(x1, y1, x2, y2, x3, y3, colour) |
Draws a filled triangle. |
draw.gradient(x, y, w, h, colourA, colourB, across) |
Draws a rectangle that fades from colourA at the top to colourB at the bottom, or from left to right when across is true. |
draw.item(id, x, y, size) |
Draws an item’s icon, 32 pixels unless you say: draw.item("minecraft:ender_pearl", 10, 10). Returns false when Citron has no icon for it. |
draw.screen() |
Returns the screen’s width and height. |
draw.worldToScreen(x, y, z) |
Returns where a point in the world is on the screen, x and y, or nil when it is behind you. |
draw.screenshare(mode) |
Chooses whether what the handler draws next shows in screen captures (below). |
The fonts are "regular", "medium" (the default), "semibold", "bold", "title" and "mono".
Drawing functions only work inside a render2d handler. draw.textWidth, draw.screen and draw.worldToScreen work anywhere.
Screen captures
Section titled “Screen captures”What a script draws follows Stream Hide like the rest of Citron: while Stream Hide is on, it stays out of OBS, Discord and other screen captures. draw.screenshare(mode) changes that for whatever the handler draws after it:
"auto"follows Stream Hide. Every handler starts on this."hide"keeps it out of captures, even with Stream Hide off. For things only you should see, such as your coordinates."show"puts it in captures, even with Stream Hide on. For an overlay meant for viewers.
The choice lasts until the handler ends, and does not carry over to other handlers or scripts. client.streamHidden() tells you whether Stream Hide is on.
events.on("render2d", function(ctx) ctx.screenshare("hide") local x, y, z = player.position() if x then ctx.text(string.format("%.0f %.0f %.0f", x, y, z), 10, 200, "#7FE3B0", 14) endend)draw3d
Section titled “draw3d”Boxes and lines in the world. The game draws them in its own picture, so blocks in front of them hide them.
| Function | What it draws |
|---|---|
draw3d.box(x1, y1, z1, x2, y2, z2, colour, filled) |
A box between two corners: its edges, or filled when filled is true. |
draw3d.block(x, y, z, colour, filled) |
The box of the block at x, y, z. |
draw3d.line(x1, y1, z1, x2, y2, z2, colour, width) |
A line, 2 wide unless you say (0.5 to 12). |
All scripts together can draw up to 2048 shapes a frame.
Because draw3d shapes are part of the game’s own picture, which every screen capture records, they are not drawn while Stream Hide is on.
A box round the nearest enemy:
events.on("render3d", function() local p = world.nearestPlayer({ enemies = true, range = 32 }) if p then draw3d.box(p.x - 0.35, p.y, p.z - 0.35, p.x + 0.35, p.y + p.height, p.z + 0.35, 0xFF5B5B) endend)