Skip to content

Class "Font"⚓︎

Constructors⚓︎

Font ()⚓︎

Font Font ( )⚓︎

Constructor for the "Font" class.

Example Code

Example usage.

1
2
3
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object
f:DrawString("Hello World!",60,50,KColor(1,1,1,1),0,true) -- render string with loaded font on position 60x50y


Functions⚓︎

Draw·String ()⚓︎

void DrawString ( string String, float PositionX, float PositionY, KColor RenderColor, int BoxWidth = 0, boolean Center = false )⚓︎

Draws a string of text to the screen Converts UTF8 to UTF16, then draws the string. Notes: The BoxWidth and Center parameters can be used for aligning the text: If BoxWidth is zero, the text will be left aligned and the center parameter will be ignored If BoxWidth is NOT zero, and the Center parameter is FALSE, then the text will be right aligned inside the BoxWidth size If BoxWidth is NOT zero, and the center parameter is TRUE, then the text will be centered inside the BoxWidth size

Bug

Calling this function with nil as either the String or RenderColor parameters will crash the game.

Example Code

Example usage.

1
2
3
4
5
6
-- In an initialization function:
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object

-- In a render function on every frame:
f:DrawString("Hello World!",60,50,KColor(1,1,1,1),0,true) -- render string with loaded font on position (60, 50)


Draw·String·Scaled ()⚓︎

void DrawStringScaled ( string String, float PositionX, float PositionY, float ScaleX, float ScaleY, KColor RenderColor, int BoxWidth = 0, boolean Center = false )⚓︎

Draws a scaled string of text on the screen. Converts UTF8 to UTF16, then draws the string.

Bug

Calling this function with nil as either the String or RenderColor parameters will crash the game.

Example Code

Example usage.

1
2
3
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object
f:DrawStringScaled("Hello World!",60,50,0.5,0.5,KColor(1,1,1,1),0,true) -- render string with loaded font on position 60x50y


Draw·String·Scaled·UTF8 ()⚓︎

void DrawStringScaledUTF8 ( string String, float PositionX, float PositionY, float ScaleX, float ScaleY, KColor RenderColor, int BoxWidth = 0, boolean Center = false )⚓︎

Draws a scaled string of Unicode text on the screen.

Bug

Calling this function with nil as either the String or RenderColor parameters will crash the game.

Example Code

Example usage.

1
2
3
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object
f:DrawStringScaledUTF8("Hello World!",60,50,0.5,0.5,KColor(1,1,1,1),0,true) -- render string with loaded font on position 60x50y


Draw·String·UTF8 ()⚓︎

void DrawStringUTF8 ( string String, float PositionX, float PositionY, KColor RenderColor, int BoxWidth = 0, boolean Center = false )⚓︎

Draws a string of Unicode text to the screen Notes: The BoxWidth and Center parameters can be used for aligning the text: If BoxWidth is zero, the text will be left aligned and the center parameter will be ignored If BoxWidth is NOT zero, and the Center parameter is FALSE, then the text will be right aligned inside the BoxWidth size If BoxWidth is NOT zero, and the center parameter is TRUE, then the text will be centered inside the BoxWidth size

Bug

Calling this function with nil as either the String or RenderColor parameters will crash the game.

Example Code

Example usage.

1
2
3
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object
f:DrawStringUTF8("Hello World!",60,50,KColor(1,1,1,1),0,true) -- render string with loaded font on position 60x50y


Get·Baseline·Height ()⚓︎

int GetBaselineHeight ( )⚓︎

Get the number of pixels from the absolute top of the line to the base of the characters


Get·Character·Width ()⚓︎

int GetCharacterWidth ( char Character )⚓︎

Returns the width of a specific character


Get·Line·Height ()⚓︎

int GetLineHeight ( )⚓︎

Get the distance in pixels between each line of text


Get·String·Width ()⚓︎

int GetStringWidth ( string String )⚓︎

Converts UTF8 to UTF16 and returns string width

Bug

Calling this function with nil as parameter will crash the game.


Get·String·Width·UTF8 ()⚓︎

int GetStringWidthUTF8 ( string String )⚓︎

returns string width of a Unicode text.


Is·Loaded ()⚓︎

boolean IsLoaded ( )⚓︎

Returns whether a font is loaded or not.


Load ()⚓︎

void Load ( string FilePath )⚓︎

Loads a font.

Note

To check that the font actually got loaded, call the IsLoaded() method afterwards.

Example Code

Example usage.

1
2
3
local f = Font() -- init font object
f:Load("font/terminus.fnt") -- load a font into the font object
f:DrawString("Hello World!",60,50,KColor(1,1,1,1),0,true) -- render string with loaded font on position 60x50y


Set·Missing·Character ()⚓︎

void SetMissingCharacter ( char MissingCharacter )⚓︎

Converts UTF8 to UTF16, then draws Sets the missing character to be used by the font (the character used when missing characters are encountered)


Unload ()⚓︎

void Unload ( )⚓︎

Unloads all our data from memory



Last update: March 19, 2023