Skip to main content

SetTextFont

Description

Sets the font to be used for text drawing. Can accept either a font object created with CreateFont or a string representing a system font name. When using a string, the font is automatically created and cached internally on a per-script basis.

function SetTextFont(font) --[[ ... ]] end

Parameters

  • font: string - A font object returned by CreateFont or a string with the system font name

Return Values

  • font: - Returns the font object that will be used for text drawing.

Example

-- Using a font object
local customFont = CreateFont('path/to/font.ttf')
SetTextFont(customFont)

-- Draw text with the selected font
SetTextPosition(0.5, 0.5)
SetTextScale(1.0)
DrawText("This text uses the selected font")
-- Using a string (automatically creates and caches the font)
SetTextFont("Arial")

-- Draw text with the selected font
SetTextPosition(0.5, 0.5)
SetTextScale(1.0)
DrawText("This text uses the selected font")

See Also