Skip to main content

Text

Description:

  Drawable text.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: Text): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: Text, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: Text): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

set

Type: Function.

Description:

  Replaces the contents of the Text object with a new unformatted string.

Signature:

set: function(self: Text, text: string)

Parameters:

ParameterTypeDescription
textstringThe new string of text to use.

set

Type: Function.

Description:

  Replaces the contents of the Text object with a new unformatted string.

Signature:

set: function(self: Text, text: {string | Color})

Parameters:

ParameterTypeDescription
text{stringColor}

setf

Type: Function.

Description:

  Replaces the contents of the Text object with a new formatted string.

Signature:

setf: function(self: Text, text: string, wrap_limit: number, align: AlignMode)

Parameters:

ParameterTypeDescription
textstringThe new string of text to use.
wrap_limitnumberThe maximum width in pixels of the text before it gets automatically wrapped to a new line.
alignAlignModeThe alignment of the text.

setf

Type: Function.

Description:

  Replaces the contents of the Text object with a new formatted string.

Signature:

setf: function(self: Text, text: {string | Color}, wrap_limit: number, align: AlignMode)

Parameters:

ParameterTypeDescription
text{stringColor}
wrap_limitnumberThe maximum width in pixels of the text before it gets automatically wrapped to a new line.
alignAlignModeThe alignment of the text.

add

Type: Function.

Description:

  Adds additional colored text to the Text object at the specified position.

Signature:

add: function(self: Text, text: ColoredText, transform: Transform): integer

Parameters:

ParameterTypeDescription
textColoredTextThe text to add to the object.
transformTransformThe position of the new text on the x-axis. (Default: 0.)

Returns:

Return TypeDescription
integerindex — An index number that can be used with Text:getWidth or Text:getHeight.

add

Type: Function.

Description:

  Adds additional colored text to the Text object at the specified position.

Signature:

add: function(self: Text, text: ColoredText, x?: number, y?: number, angle?: number, scale_x?: number, scale_y?: number, origin_x?: number, origin_y?: number, shear_x?: number, shear_y?: number): integer

Parameters:

ParameterTypeDescription
textColoredTextA table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
xnumberThe position of the new text on the x-axis. (Default: 0.)
ynumberThe position of the new text on the y-axis. (Default: 0.)
anglenumberThe orientation of the new text in radians. (Default: 0.)
scale_xnumberScale factor on the x-axis. (Default: 1.)
scale_ynumberScale factor on the y-axis. (Default: sx.)
origin_xnumberOrigin offset on the x-axis. (Default: 0.)
origin_ynumberOrigin offset on the y-axis. (Default: 0.)
shear_xnumberShearing / skew factor on the x-axis. (Default: 0.)
shear_ynumberShearing / skew factor on the y-axis. (Default: 0.)

Returns:

Return TypeDescription
integerindex — An index number that can be used with Text:getWidth or Text:getHeight.

addf

Type: Function.

Description:

  Adds additional formatted / colored text to the Text object at the specified position.

-- The word wrap limit is applied before any scaling, rotation, and other coordinate transformations. Therefore the amount of text per line stays constant given the same wrap limit, even if the scale arguments change.

Signature:

addf: function(self: Text, text: ColoredText, wrap_limit: number, align: AlignMode, transform: Transform): integer

Parameters:

ParameterTypeDescription
textColoredTextThe text to add to the object.
wrap_limitnumberThe maximum width in pixels of the text before it gets automatically wrapped to a new line.
alignAlignModeThe alignment of the text.
transformTransformThe position of the new text (x-axis).

Returns:

Return TypeDescription
integerindex — An index number that can be used with Text:getWidth or Text:getHeight.

addf

Type: Function.

Description:

  Adds additional formatted / colored text to the Text object at the specified position.

-- The word wrap limit is applied before any scaling, rotation, and other coordinate transformations. Therefore the amount of text per line stays constant given the same wrap limit, even if the scale arguments change.

Signature:

addf: function(self: Text, text: ColoredText, wrap_limit: number, align: AlignMode, x?: number, y?: number, angle?: number, scale_x?: number, scale_y?: number, origin_x?: number, origin_y?: number, shear_x?: number, shear_y?: number): integer

Parameters:

ParameterTypeDescription
textColoredTextA table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
wrap_limitnumberThe maximum width in pixels of the text before it gets automatically wrapped to a new line.
alignAlignModeThe alignment of the text.
xnumberThe position of the new text (x-axis).
ynumberThe position of the new text (y-axis).
anglenumberOrientation (radians). (Default: 0.)
scale_xnumberScale factor (x-axis). (Default: 1.)
scale_ynumberScale factor (y-axis). (Default: sx.)
origin_xnumberOrigin offset (x-axis). (Default: 0.)
origin_ynumberOrigin offset (y-axis). (Default: 0.)
shear_xnumberShearing / skew factor (x-axis). (Default: 0.)
shear_ynumberShearing / skew factor (y-axis). (Default: 0.)

Returns:

Return TypeDescription
integerindex — An index number that can be used with Text:getWidth or Text:getHeight.

clear

Type: Function.

Description:

  Clears the contents of the Text object.

Signature:

clear: function(self: Text)

setFont

Type: Function.

Description:

  Replaces the Font used with the text.

Signature:

setFont: function(self: Text, font: Font)

Parameters:

ParameterTypeDescription
fontFontThe new font to use with this Text object.

getFont

Type: Function.

Description:

  Gets the Font used with the Text object.

Signature:

getFont: function(self: Text): Font

Returns:

Return TypeDescription
FontThe font used with this Text object.

getWidth

Type: Function.

Description:

  Gets the width of the text in pixels.

Signature:

getWidth: function(self: Text): number

Returns:

Return TypeDescription
numberwidth — The width of the text. If multiple sub-strings have been added with Text:add, the width of the last sub-string is returned.

getWidth

Type: Function.

Description:

  Gets the width of the text in pixels.

Signature:

getWidth: function(self: Text, index: integer): number

Parameters:

ParameterTypeDescription
indexintegerAn index number returned by Text:add or Text:addf.

Returns:

Return TypeDescription
numberThe width of the sub-string (before scaling and other transformations).

getHeight

Type: Function.

Description:

  Gets the height of the text in pixels.

Signature:

getHeight: function(self: Text): number

Returns:

Return TypeDescription
numberheight — The height of the text. If multiple sub-strings have been added with Text:add, the height of the last sub-string is returned.

getHeight

Type: Function.

Description:

  Gets the height of the text in pixels.

Signature:

getHeight: function(self: Text, index: integer): number

Parameters:

ParameterTypeDescription
indexintegerAn index number returned by Text:add or Text:addf.

Returns:

Return TypeDescription
numberheight — The height of the text. If multiple sub-strings have been added with Text:add, the height of the last sub-string is returned.

getDimensions

Type: Function.

Description:

  Gets the width and height of the text in pixels.

Signature:

getDimensions: function(self: Text): number, number

Returns:

Return TypeDescription
numberwidth — The width of the text. If multiple sub-strings have been added with Text:add, the width of the last sub-string is returned.
numberheight — The height of the text. If multiple sub-strings have been added with Text:add, the height of the last sub-string is returned.

getDimensions

Type: Function.

Description:

  Gets the width and height of the text in pixels.

Signature:

getDimensions: function(self: Text, index: integer): number, number

Parameters:

ParameterTypeDescription
indexintegerAn index number returned by Text:add or Text:addf.

Returns:

Return TypeDescription
numberThe width of the sub-string (before scaling and other transformations).
numberThe height of the sub-string (before scaling and other transformations).