Draw 2D
Immediate-mode 2D overlay shapes (lines, circles, rectangles, polylines) in world or screen space.
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.
| Parameters | Type | Description |
|---|---|---|
a | table | Start {x, y}. |
b | table | End {x, y}. |
color | table | {r, g, b, a} in 0..1 (each defaults to 1). |
thickness | number | Line thickness (default 1). |
space | string | "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).
| Parameters | Type | Description |
|---|---|---|
center | table | Center {x, y}. |
radius | number | Radius. |
color | table | {r, g, b, a} in 0..1 (each defaults to 1). |
thickness | number | Line thickness (default 1). |
space | string | "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.
| Parameters | Type | Description |
|---|---|---|
min | table | Corner {x, y}. |
max | table | Opposite corner {x, y}. |
color | table | {r, g, b, a} in 0..1 (each defaults to 1). |
thickness | number | Line thickness (default 1). |
space | string | "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.
| Parameters | Type | Description |
|---|---|---|
points | table | Array of {x, y}; at least 2 points or nothing is drawn. |
color | table | {r, g, b, a} in 0..1 (each defaults to 1). |
closed | boolean | Close the shape (default false). |
thickness | number | Line thickness (default 1). |
space | string | "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)