Game Development Reference
In-Depth Information
Drawing Images
You've already learned that the way to create a display object on the screen is by creating a
MOAIProp that needs to be added to a layer. Similarly, to display images, you create a MOAIProp object
by creating a quad object for which you set the texture as the image you want to load. This can then
be set as the deck object.
gfxQuad = MOAIGfxQuad2D.new ()
gfxQuad:setTexture ( "moai.png" )
gfxQuad:setRect ( -64, -64, 64, 64 )
prop = MOAIProp2D.new ()
MOAIImage class to create a blank image that can be used as a canvas, like so:
Note The image that you create must be a power of 2—that is, the width and height must be a
number that is a power of 2. While creating an image dynamically, if you create an image that does not
conform to the power of 2, you can use the function padToPow2 to pad the image to the appropriate
size as required.
This image object created can then be used to create the Quad2D object, which is then added to
the layer.
gfxQuad = MOAIGfxQuad2D.new ()
gfxQuad:setTexture ( image )
gfxQuad:setRect ( -64, -64, 64, 64 )
prop = MOAIProp2D.new ()
prop:setDeck ( gfxQuad )
layer:insertProp ( prop )
This code will display nothing, as the image created is a blank image. In the following code we
create a bitmap in memory and display that to the screen. This is a good way to create dynamic
images via code.
local image = MOAIImage.new()
image:init(25, 40)
image:padToPow2()
 
Search WWH ::




Custom Search