Skip to content

Engine.interface

Text and HUD elements drawn on screen. They stay on screen until they are removed or the plugin unloads; there is no need to draw them every frame.

Functions

Engine.interface.addText

local text = Engine.interface.addText(text, x, y, options)

Adds a text to the screen. x and y are distances from the anchored corner, towards the center, in the units of the interface canvas, which is 480 units tall. On the "hud" layer they are measured in each player's HUD pane. With the "center" anchor they are offsets from the center and can be negative. Text is not wrapped.

options is an optional table. Options are fixed once the text is added; to change one, remove the text and add a new one.

Option Type Default Description
color table opaque white a, r, g and b, each from 0 to 1. Channels left out count as 0.
font TagHandle the console font A font or vector_font tag.
style string "plain" "plain", "bold", "italic", "condense" or "underline".
justification string the anchored side "left", "right" or "center".
anchor string "topLeft" "topLeft", "topRight", "bottomLeft", "bottomRight" or "center".
layer string "hud" "hud" draws on the HUD of every local player, whenever the HUD is drawn. "ui" draws over the whole interface, menus included.
shadow boolean true Whether the text has a drop shadow.
flags integer Raw text drawing flags.

Returns an InterfaceText:

Method Description
setText(text) Changes the text.
remove() Removes the text. Calling it again raises an error.

Engine.interface.addHudStaticElement

local element = Engine.interface.addHudStaticElement(anchor, staticElement, flags, flashStartTime)

Adds a static element to the HUD of every local player, taken from a HUD interface tag.

Parameter Type Description
anchor HudInterfaceAnchor Corner or edge of the screen the element is placed from.
staticElement HudInterfaceStaticElementDefinition The element, from a HUD interface tag.
flags HudDrawFlags, optional Drawing flags.
flashStartTime integer, optional Tick at which the element started flashing, or -1.

Returns a HudStaticElement with setFlags(flags), setFlashStartTime(tick) and remove(). The element is removed when the map changes, since its definition belongs to the map.

Engine.interface.getCursorPosition

local position = Engine.interface.getCursorPosition()

Returns the position of the menu cursor as a Point2dInt, in the same space as texts on the "ui" layer.

Example

local clock = Engine.interface.addText("", 8, 8, {anchor = "topRight", color = {a = 1, r = 1, g = 1, b = 0.6}})

Balltze.addEventListener("tick", function()
    clock:setText(os.date("%H:%M"))
end)