draw

HUD drawing: text, shapes, bars, over the game.

Draws straight onto the screen, over the game and under every window. Call these from a draw event handler; they draw for that one frame. Coordinates are UI units from the top-left corner (draw.screen() is the size). Colours: see Color below.

Functions

# draw.text(x, y, text, color?, size?, align?)

Text with a soft shadow.

ParameterType
xnumber
ynumber
textany
color optionalColordefault white
size optionalnumberfont size (default the UI font)
align optionalstring"left" (default), "center" or "right" of x
draw.text(20, 20, "Score: " .. score, "#ffd040", 26)

# draw.textSize(text, size?) → number, number

The size text would take.

ParameterType
textstring
size optionalnumber
Returns
numberwidth
numberheight

# draw.line(x1, y1, x2, y2, color?, thickness?)

A line.

ParameterType
x1number
y1number
x2number
y2number
color optionalColor
thickness optionalnumberdefault 1

# draw.rect(x, y, w, h, color?, thickness?, rounding?)

A rectangle outline.

ParameterType
xnumber
ynumber
wnumber
hnumber
color optionalColor
thickness optionalnumber
rounding optionalnumbercorner radius

# draw.fillRect(x, y, w, h, color?, rounding?)

A filled rectangle.

ParameterType
xnumber
ynumber
wnumber
hnumber
color optionalColor
rounding optionalnumber

# draw.circle(x, y, r, color?, thickness?)

A circle outline.

ParameterType
xnumber
ynumber
rnumberradius
color optionalColor
thickness optionalnumber

# draw.fillCircle(x, y, r, color?)

A filled circle.

ParameterType
xnumber
ynumber
rnumber
color optionalColor

# draw.fillTriangle(x1, y1, x2, y2, x3, y3, color?)

A filled triangle (arrows, markers).

ParameterType
x1number
y1number
x2number
y2number
x3number
y3number
color optionalColor

# draw.bar(x, y, w, h, fraction, color?, background?)

A filled bar: health bars, progress.

ParameterType
xnumber
ynumber
wnumber
hnumber
fractionnumber0-1
color optionalColordefault green
background optionalColordefault translucent black
draw.bar(sx - 40, sy, 80, 8, c.health / c.maxHealth, "red")

# draw.screen() → number, number

The screen size in UI units.

Returns
numberwidth
numberheight

# draw.image(file, x, y, w?, h?, color?) → boolean

Draws an image: PNG (any common kind, not interlaced) or TGA. Loaded on first use and kept.

ParameterType
filestringa PNG or TGA file of your mod (path in its folder), or a game file by name
xnumber
ynumber
w optionalnumberwidth (default: the image's)
h optionalnumberheight (default: keeps the shape)
color optionalColortint, and alpha for transparency
Returns
booleanfalse when the image could not be loaded (logged once)
draw.image("hud/compass.png", e.width - 140, 20, 120)
draw.image("hud/blood.png", 0, 0, e.width, e.height, {1, 1, 1, 0.4})

# draw.imageSize(file) → integer?, integer?

An image's size in pixels (nothing when it cannot be loaded).

ParameterType
filestring
Returns
integer?width
integer?height