Rendering¶
Draw from your script's Render callback. Make game decisions in Update,
keep the values you want to show, and draw them in Render.
local status = "Ready"
function Render()
RenderTopRightText(status, 12, 12, 14, Color("#00FF00"), true)
local tc = GetAssignedPlayer():GetTownCenters()[1]
if tc then RenderWorldCircle(tc:GetPosition(), 8, Color("#FFFF00")) end
end
Arguments. Screen positions are { x, y } in pixels. World positions are
{ x, y, z } in tiles, as Object:GetPosition() returns them. Missing
coordinates read as 0. color is a Color or an ARGB
integer and defaults to opaque white; thickness defaults to 1; segments
defaults to 32; size defaults to the current font size. Draw calls return
nothing, and draw nothing when the view or minimap isn't available.
Background renders. Scripts normally run on a background worker. While it
is on, every Render (on the worker, or on the frame thread when the worker is
idle) records its drawing and WololoLabs replays it every frame until the
next Render, projecting world shapes with the current camera. In such a
recorded pass:
GetScreenSizereturns the size the last drawn frame had, so screen-relative placement is the same in every pass (0, 0only before the first frame);- the queries
GetZoom,GetCameraPosition,IsOnScreen,IsWorldPosOnScreen,WorldToScreenandWorldToMinimapreturn zero,falseornil, so prefer the world and minimap draw calls over projecting positions yourself; RenderObjectBounds,RenderObjectBoundsFilled,RenderMinimapRectandRenderMinimapRectFilleddraw nothing.
On screen¶
| Call | Draws |
|---|---|
RenderText(text, position[, size[, color[, center[, border]]]]) |
Text. center = true centres it on position; border = true adds a black outline. |
RenderTopRightText(text[, marginX = 12[, marginY = 12[, size[, color[, border]]]]]) |
Text anchored to the top-right corner. |
RenderTextTable(id, rows, origin[, style]) |
A table with its top-left at origin; see Text tables. Returns width, height of the table named id as last drawn, 0, 0 before its first frame, so an overlay frame can fit it. |
RenderLine(from, to[, color[, thickness]]) |
A line. |
RenderCircle(center, radius[, color[, thickness[, segments]]]) |
A circle outline. |
RenderCircleFilled(center, radius[, color[, segments]]) |
A filled circle. |
RenderRect(min, max[, color[, rounding[, cornerFlags[, thickness]]]]) |
A rectangle outline between two corners. |
RenderRectFilled(min, max[, color[, rounding[, cornerFlags]]]) |
A filled rectangle. |
In the world¶
A shape with a point that can't be projected is not drawn.
On the minimap¶
Positions are world positions; the API places them on the minimap.
View and camera¶
Text tables¶
RenderTextTable draws aligned columns of text, numbers, game icons and progress bars,
measured when the frame is drawn, so it is safe from a Render that runs on the worker.
rows is an array. Each row is an array of cells, or the string "-" for a separator
line. A row may also have color (its text colour), accent (a thin bar at its left in
that colour) and band (a background band in that colour). A cell is text, a number, or
a table:
| Cell field | Meaning |
|---|---|
text |
The cell's text. |
detail |
Smaller, dimmer text after it, such as "/3" beside a value. |
color, detailColor |
Colours for the two texts; color defaults to the row's. |
icon |
{ kind = "unit", "research" or "resource", id }: a game icon before the text; id from GetIconId. |
bar, barColor |
A progress bar, 0 to 1, after the text. |
| Style field | Meaning |
|---|---|
size, scale |
Text size in pixels (default the overlay font) and a multiple of it. |
align |
Per column: "left" (default), "right" or "center". |
background, border, rounding |
The panel behind the table; none by default. rounding defaults to 6. |
padding, columnGap, rowGap |
Spacing in pixels. |
iconScale, detailScale, barWidth |
Icon and detail size as multiples of the text size (1.25, 0.85), and bar width in pixels. |
Columns are as wide as their widest cell.
Batches and overlay frames¶
Use a batch when a script draws thousands of shapes, such as every unit on a
minimap or a box over every unit on the map. Build it in Update and draw it in Render with one call. A frame
keeps drawing the batch it was given while Update rebuilds it, so a rebuild
never changes a frame halfway.
A batch has these methods. color is a Color or an ARGB integer such as
0xAAFF0000 (cheaper: no table per shape) and defaults to opaque white.
center, from, to and anchor are tables with x, y and an optional z
(default 0), so a Vector3 from object:GetPosition() works as it is. Sizes
are in the batch's units, except dot radii and text, which stay in screen pixels.
segments is clamped to 8-192.
| Method | Does |
|---|---|
batch:AddQuadFilled(x1, y1, x2, y2, x3, y3, x4, y4[, color]) |
Adds a filled quad, corners in drawing order. |
batch:AddQuad(x1, y1, x2, y2, x3, y3, x4, y4[, color[, thickness]]) |
Adds a quad outline; thickness defaults to 1. |
batch:AddBox(center, halfWidth, halfHeight[, color[, thickness]]) |
Adds the outline of a box from center - half to center + half. |
batch:AddBoxFilled(center, halfWidth, halfHeight[, color]) |
Adds a filled box. |
batch:AddLine(from, to[, color[, thickness]]) |
Adds a line. |
batch:AddCircle(center, radius[, color[, thickness[, segments]]]) |
Adds a circle outline; segments defaults to 32. |
batch:AddCircleFilled(center, radius[, color[, segments]]) |
Adds a filled circle. |
batch:AddDot(center, pixelRadius[, color[, segments]]) |
Adds a filled circle whose radius is in screen pixels; segments defaults to 16. |
batch:AddText(text, anchor[, color[, style]]) |
Adds text at anchor. Optional style: size (default the overlay font), offsetX, offsetY (screen pixels), centered, outlined. One style table can serve every call. |
batch:AddIcon(kind, iconId, anchor[, style]) |
Adds the game's own icon, a square of screen pixels centred on anchor. kind is "unit", "research" or "resource" and iconId comes from GetIconId. Optional style: size (8 to 128, default 32), offsetX, offsetY (screen pixels), alpha (0.1 to 1, default 1), progress (0 to 1 draws a bar under the icon) and barColor. An icon with no file, or id -1, draws as ? and is logged once. |
batch:Clear() |
Removes every shape. |
batch:GetCount() |
The number of shapes. |
Both draw calls skip shapes wholly off screen. A batch holds at most 200,000 shapes. A coordinate, size, thickness, origin or scale
that is not a finite number, or a frame field that is missing, not finite, or a
width or height below 1, raises a Lua error.
With movable = true, RenderOverlayFrame shows the frame's bounds in a
transparent window the player can drag and resize, and returns where the frame
stands, which can lag a drag by a frame; rect only places a frame that has no
position yet. With movable = false it draws nothing and returns rect. The
frame does not save itself: save the result in your settings when it changes.
Use SetOverlayFrame when a setting changes or to reset a layout, never every
frame with RenderOverlayFrame's result, which would stop a drag.
Store batch corners in frame units, 0 to 1, and draw with the frame's
position as origin and its size as scale, so moving or resizing the frame
doesn't need a rebuild.
local dots = RenderBatch()
local frame = { x = 1555, y = 890, width = 350, height = 190 }
function Update()
dots:Clear()
dots:AddQuadFilled(0.49, 0.49, 0.49, 0.51, 0.51, 0.51, 0.51, 0.49, 0xAAFF0000)
end
function Render()
local placed = RenderOverlayFrame("my-frame", frame, true)
RenderDrawBatch(dots, { x = placed.x, y = placed.y }, { x = placed.width, y = placed.height })
end
A batch of map positions drawn with RenderDrawWorldBatch follows the camera
the same way:
local boxes = RenderBatch()
local nameStyle = { size = 16, offsetY = 30, centered = true, outlined = true }
function Update()
boxes:Clear()
for _, object in ipairs(GetIndexedObjects(2, -1) or {}) do
local position = object:GetPosition()
if position then
boxes:AddBox(position, 0.5, 0.5, 0xFFFF0000, 2)
boxes:AddText(object:GetMasterName(), position, 0xFFFFFFFF, nameStyle)
end
end
end
function Render()
RenderDrawWorldBatch(boxes)
end
The view can be unavailable while the game changes state; keep Render free
of game logic so a missed frame doesn't matter.