- Corona SDK Mobile Game Development:Beginner's Guide
- Michelle M. Fernandez
- 413字
- 2021-08-06 19:59:47
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
- 筆記本電腦使用、維護與故障排除實戰
- Effective STL中文版:50條有效使用STL的經驗(雙色)
- Mastering Delphi Programming:A Complete Reference Guide
- Deep Learning with PyTorch
- 計算機組裝·維護與故障排除
- 現代辦公設備使用與維護
- 從零開始學51單片機C語言
- 筆記本電腦維修不是事兒(第2版)
- Rapid BeagleBoard Prototyping with MATLAB and Simulink
- 電腦橫機使用與維修
- 筆記本電腦維修技能實訓
- 計算機組成技術教程
- MicroPython Cookbook
- Applied Deep Learning with Keras
- Hands-On Game Development with WebAssembly