Game Development Reference
In-Depth Information
Beyond Hello World: Creating a Rectangle on the Screen
In the same manner, we can create a rectangle on the screen, as shown in Figure 8-5 .
local rect_01 = display.newRect( 50, 50, 200, 200 )
Figure 8-5. A rectangle on the device with the default fill colors
This shall create a rectangle on the screen that is placed at position 50, 50 and has the dimensions
200×200. The display elements, when created, are assigned the default settings; therefore, we see a
white rectangle on the screen even if we do not specify a fill.
We can change some of the attributes, such as the fill color, outline color, and alpha (transparency),
as well as the scale and the rotation of the rectangle. Let's modify the rectangle to manipulate all of
these.
rect_01:setFillColor(255,0,0)
setFillColor takes the color as four values: red (R), green (G), blue (B), and the optional alpha (A).
The values for the colors are in the range of 0 to 255, and the alpha is opaque (255) by default.
 
Search WWH ::




Custom Search