Game Development Reference
In-Depth Information
Displaying Text
This section will describe how to display text to the screen in your application. Gideros Studio allows
you to use custom fonts in your application, and it works with both TrueType and bitmapped fonts.
Note that if you want to use a custom font, then it needs to be loaded before use.
Note Gideros Studio comes with Gideros Font Creator, an application for creating bitmapped fonts that
can be used with Gideros Studio.
The first thing you need to do to display text is create a text field, which you can do as follows:
-- To use the default font, pass a nil value for the font parameter
local text = TextField.new(nil, "Hello World")
text:setPosition(10,10)
stage:addChild(text)
text:setText("Hello from Gideros Studio")
-- Change the text
Here, we create a new text field with nil as the parameter, which will use the default font. Then
we position the text on the screen. Text in Gideros is displayed using baseline font . Simply, the y
parameter is where the base of the font is aligned, which may take a while to get used to. For
example, if we do not position the text at position 10 from the top, the text might not be visible. Then
we add the text to the stage and change the text displayed.
The TextField object can be modified like any other display object. The text color can be set using
the function object:setTextColor( colour ) , where colour is a hexadecimal value derived from b + g *
256 + r * 65536 , and r , g , and b represent the red, green, and blue values of the color, respectively.
To make the preceding text red, we use the following:
-- To use the default font, pass a nil value for the font parameter
local text = TextField.new(nil, "Hello World")
text:setPosition(10,50)
text:setTextColor(0xff0000)
stage:addChild(text)
text:setText("Hello from Gideros Studio")
-- Change the text
text:setScale(2,2)
When this is run, the player displays the text “Hello from Gideros Studio” in red and at twice the size
of the default font, as shown in Figure 9-12 .
 
Search WWH ::




Custom Search