16. Table text

A table text inherit from renderizable and implement all methods as usual. A text is created by a font using the method addText. An animation has a shader table by default which can be accessed by getShader method. Also an animation for text does not change the frame (there is no this concept on text), and instead of this, change how is drew the text on screen. A text can have more than one animation simultaneous (use setWildCard to do it).

16.1. text methods

16.1.1. text getSize

getSize(boolean* forceCalc)

Get the size of text, Do NOT consider the rotation. It considers the scale.

Returns

number width, number height - dimension of text.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Some text here','2dw')
local width, height = tText:getSize()
print(width,height)

local width, height = tText:getSize(true) -- force recalculate
print(width,height)

Note

Only if the text is 3D there will be a depth value.

getSize(string other_text)

Get the size of the string sent as text, Do NOT consider the rotation. It considers the scale.

Parameters

stringtext to be calculated.

Returns

number width, number height - dimension of text.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Some text here','2dw')
local width, height = tText:getSize('Other text\nHere is a new line!')
print(width,height)

Note

Only if the text is 3D there will be a depth value.

16.1.2. text getSizeText

getSizeText(text other_text)

Get the size of text NOT considering the rotation. It considers the scale.

Parameters

stringtext to be calculated.

Returns

number width, number height - dimension of text.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Some text here','2dw')
local width, height = tText:getSizeText('Other other text\nHere is a new line!')
print(width,height)

Note

Only if the text is 3D there will be a depth value.

16.1.3. text setWildCard

setWildCard(string wildCard)

Set the wildCard to change the animations in the same text.

Parameters

stringwildCard any character.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Hello world','2dw')
tText:setWildCard('#')
tText.text =  '#1#Hello #2#World!' --new text with wild-card.

Note

In the example we are expecting the text has at least two animation.
#1# is the number for animation ‘one’.
#2# is the number for animation ‘two’.

16.2. text attributes

text [read / write]

Access the text member for read / write.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Hello world','2dw')
print(tText.text) -- Hello world
tText.text =  'Welcome to my example!' --new text with
print(tText.text) -- Welcome to my example!
align [read / write]

Access the align from text member for read / write. The default is aligned to left.

The valid values are: left, right and center.

Example:

tArial15 = font:new('Arial15.fnt') -- load a file previously created by the engine.
tText = tArial15:add('Hello world aligned!\nNew line','2dw')
print(tText.align) -- left
tText.align =  'center'

16.3. Creating a text programmatically

To create a text programmatically you need create a font.

An example can be found here.