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.

In the game's own GUI pass (the gui event and a page's draw function, API 3) draw.sprite, draw.text, draw.textSize, draw.fillRect, draw.rect, draw.line and draw.screen use the game's renderer and its units instead: the screen 320 high, y from the top, the game's fonts; the other functions work only in draw.

Functions

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

Text with a soft shadow. In the gui event with the game's fonts, size = the text height in game units (default the font's).

ParameterType
xnumber
ynumber
textany
color optionalColordefault white
size optionalnumberfont size (default the UI font)
align optionalstring"left" (default), "center" or "right" of x
font optionalstringin the gui event: one of the game's fonts (ofs15 default, ofs13, lith18, ccra14)
draw.text(20, 20, "Score: " .. score, "#ffd040", 26)

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

The size text would take.

ParameterType
textstring
size optionalnumber
font optionalstringone of the game's fonts: the size in game units
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

# draw.sprite(name, x, y, options?)

since API 3

Draws one of the game's sprites. In the gui event in game units, inside the game's GUI; in the draw event in UI units, as large as the game shows it, over everything.

ParameterType
namestringa sprite of the game (ui/*.cfg: button_dino_active_9, icon_radar ...), of your sprite file, or a .tga file
xnumberleft edge (centre with center = true)
ynumbertop edge
options optionaltablescale, w, h (size), color (tint), angle (degrees), center, flipX, flipY, layer (gui pass)
on("gui", function() draw.sprite("button_weapon_active_5", 20, 40, {scale = 0.5}) end)

# draw.spriteSize(name) → number|nil, number|nil

since API 3

A sprite's size (as menu.spriteSize).

ParameterType
namestring
Returns
number|nilwidth in game units
number|nilheight