Caffeine

Draw 2D

Reference UI Last updated: Lua 5 · Dryad 0

Immediate-mode 2D overlay shapes (lines, circles, rectangles, polylines) in world or screen space.

All namespaces

Namespace: caffeine.draw2d

beginFrame#

Lua: caffeine.draw2d.beginFrame

text
beginFrame()

Starts a new overlay frame, clearing previous draw2d shapes. Call it once at the start of drawing.

Returns: none

Example

lua
caffeine.draw2d.beginFrame()

line#

Lua: caffeine.draw2d.line

text
line(a, b, color[, thickness[, space]])

Draws a line in the 2D overlay.

ParametersTypeDescription
atableStart {x, y}.
btableEnd {x, y}.
colortable{r, g, b, a} in 0..1 (each defaults to 1).
thicknessnumberLine thickness (default 1).
spacestring"world" (default) or "screen".

Returns: none

Example

lua
caffeine.draw2d.line({x=0,y=0},{x=5,y=5},{r=1,g=0,b=0,a=1}, 2)

circle#

Lua: caffeine.draw2d.circle

text
circle(center, radius, color[, thickness[, space]])

Draws a circle outline (32 segments).

ParametersTypeDescription
centertableCenter {x, y}.
radiusnumberRadius.
colortable{r, g, b, a} in 0..1 (each defaults to 1).
thicknessnumberLine thickness (default 1).
spacestring"world" (default) or "screen".

Returns: none

Example

lua
caffeine.draw2d.circle({x=0,y=0}, 3, {r=0,g=1,b=0,a=1})

rect#

Lua: caffeine.draw2d.rect

text
rect(min, max, color[, thickness[, space]])

Draws a rectangle outline.

ParametersTypeDescription
mintableCorner {x, y}.
maxtableOpposite corner {x, y}.
colortable{r, g, b, a} in 0..1 (each defaults to 1).
thicknessnumberLine thickness (default 1).
spacestring"world" (default) or "screen".

Returns: none

Example

lua
caffeine.draw2d.rect({x=-1,y=-1},{x=1,y=1},{r=1,g=1,b=0,a=1})

poly#

Lua: caffeine.draw2d.poly

text
poly(points, color[, closed[, thickness[, space]]])

Draws a polyline or polygon outline.

ParametersTypeDescription
pointstableArray of {x, y}; at least 2 points or nothing is drawn.
colortable{r, g, b, a} in 0..1 (each defaults to 1).
closedbooleanClose the shape (default false).
thicknessnumberLine thickness (default 1).
spacestring"world" (default) or "screen".

Returns: none

Example

lua
caffeine.draw2d.poly({{x=0,y=0},{x=2,y=0},{x=1,y=2}}, {r=1,g=1,b=1,a=1}, true)