Skip to main content
Version: 9.0.3

CANVAS:draw_text

CANVAS:draw_text(text, attrs)

Draw a string within the canvas directed by the user specified properties.

Parameters​

ParameterTypeDescription
text#stringThe text string to display
attrs#tableA table of properties containing information about how to draw the text (see Text Attributes Table).

Text Attributes Table​

KeyDescription
fontThe font to use to render the text (required, no default).
xThe x position of the upper left corner of the image (default 0).
yThe y position of the upper left corner of the image (default 0).
sizeThe point size to render the text at (default 18).
colorThe color to render the text in (default black:0x00000).
rotationThe angle in degrees to render the text at (default 0).

Example​

-- Draw a hello world string centered on the canvas
function DrawCenteredText(name)
local msg = "Hello World"
local canvas = gre.get_canvas(name)
local size = canvas:get_dimensions()
local attrs = {}
attrs.font = "fonts/RobotoBold.ttf"
attrs.size = 24
local strSize = gre.get_string_size(attrs.font, attrs.size, msg, 0)
attrs.x = (size.width - strSize.width) / 2
attrs.y = (size.height - strSize.height) / 2
canvas:draw_text("Hello World", attrs)
end