Game Development Reference
In-Depth Information
gfxQuad = MOAIGfxQuad2D.new ()
gfxQuad:setTexture ( "moai.png" )
gfxQuad:setRect ( -64, -64, 64, 64 )
prop = MOAIProp2D.new ()
prop:setDeck ( gfxQuad )
prop:setLoc ( 0, 80 )
layer:insertProp ( prop )
Compared to Corona SDK and Gideros Studio, this may seem a bit excessive for displaying an image
on the screen. This is the reason why Moai is known as the tool for professional developers. It offers
low-level access to a very rich API. However, that does not mean that hobbyist developers cannot
use Moai. As mentioned previously, you can use the RapaNui library, which gives developers an easy-
to-use high-level wrapper over the lower-level API of Moai. RapaNui wraps all of the Moai functions in
easier-to-use functions and reduces the number of lines of code you need to write to get things done.
Quads can also be pinned , or as it is described in Moai, the pivot point can be set; the pivot point
is used as the point around which the quad is rotated, where 0, 0 is the center (by default). This is
similar to the anchorPoint with Gideros or the referencePoint with Corona
prop:setPiv(xCenter, yCenter)
Displaying Text
Text can be displayed in Moai using either TrueType or bitmap fonts. MOAITextBox is the class that
allows for working with text in Moai.
TrueType Fonts
The easiest way to display text is using TrueType font. You can create a new font object using the
MOAIFont class and pass it the characters to load from the font, the size (in points), and the dpi of the font.
charcodes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.?!:()&/-"
font = MOAIFont.new()
font:loadFromTTF( 'arial.ttf', charcodes, 12, 163 )
Then you can create a text box to display the text using MOAITextBox :
textbox = MOAITextBox.new()
textbox:setFont(font)
textbox:setRect(-160, -80, 160, 80)
textbox:setLoc(0,160)
textbox:setAlignment(MOAITextBox.CENTER_JUSTIFY)
layer:insertProp( textbox )
textbox:setString( "Hello World from MOAI" )
 
Search WWH ::




Custom Search