Time for some shapes
Another way of creating display objects is using vector objects. You can use vector objects to create shapes, such as a rectangle, rounded rectangle, and circle by using the following:
display.newRect( [parentGroup,] left, top, width, height )
creates a rectangle usingwidth
byheight
. Location starts from the top-left corner of the device screen usingleft
andtop
as your coordinates of placement.display.newRoundedRect( [parentGroup,] left, top, width, height, cornerRadius )
creates a rounded rectangle usingwidth
byheight
. Location starts from the top-left corner of the device screen usingleft
andtop
as your coordinates of placement. Rounding off the corners usescornerRadius
.display.newCircle( [parentGroup,] xCenter, yCenter, radius )
creates a circle usingradius
centered atxCenter
,yCenter
.
Applying stroke width, fill color, and stroke color
All vector objects can be outlined using strokes. You can set the stroke width, fill color and stroke color.
object.strokeWidth
—Creates the stroke width in pixels.object:setFillColor( r, g, b [, a] )
—Using ther,g,b
codes between 0 and 255.a
refers to the alpha, which is optional and defaulted at 255.object:setStrokeColor( r, g, b [, a] )
—Using ther,g,b
codes between 0 and 255.a
refers to the alpha, which is optional and defaulted at 255.
The following is an example of displaying vector objects using strokes:
local rect = display.newRect(110, 100, 250, 250) rect:setFillColor(255, 255, 255) rect:setStrokeColor(45, 180, 100) rect.strokeWidth = 10
Text, text, text
In Chapter 1, Getting Started With Corona SDK, we created the Hello World application using a text display object. Let's go in detail on how text is implemented onscreen.
display.newText( [parentGroup,] string, x, y, font, size )
creates a text object using x
and y
values. There is no text color by default. In the font
parameter, apply any of the font names in the library. The size
parameter displays the size of the text. Some of the default constants can be used if you don't want to apply a font name:
native.systemFont
native.systemFontBold
Applying color and string value
The size, color, and text fields can be set or retrieved in text display objects.
object.size
—The size of the textobject:setTextColor( r, g, b [, a] )
—Using ther,g,b
codes between 0 and 255.a
refers to the alpha, which is optional and defaulted at 255object.text
—Contains the text of the textfield. It allows you to update a string value for a test object