官术网_书友最值得收藏!

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 using width by height. Location starts from the top-left corner of the device screen using left and top as your coordinates of placement.
  • display.newRoundedRect( [parentGroup,] left, top, width, height, cornerRadius ) creates a rounded rectangle using width by height. Location starts from the top-left corner of the device screen using left and top as your coordinates of placement. Rounding off the corners uses cornerRadius.
  • display.newCircle( [parentGroup,] xCenter, yCenter, radius ) creates a circle using radius centered at xCenter, 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 the r,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 the r,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
Applying stroke width, fill color, and stroke color

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 text
  • object:setTextColor( r, g, b [, a] )—Using the r,g,b codes between 0 and 255. a refers to the alpha, which is optional and defaulted at 255
  • object.text—Contains the text of the textfield. It allows you to update a string value for a test object
主站蜘蛛池模板: 张家港市| 肥西县| 治县。| 龙胜| 兰州市| 津市市| 岳西县| 新泰市| 尼木县| 玛纳斯县| 宝坻区| 沁源县| 平度市| 城步| 靖州| 黑山县| 新绛县| 开江县| 泌阳县| 肇州县| 徐汇区| 马鞍山市| 绥德县| 武山县| 淄博市| 沙湾县| 越西县| 澄城县| 莲花县| 大埔区| 莱州市| 聂荣县| 榆林市| 德格县| 绵竹市| 南乐县| 铁力市| 克拉玛依市| 济阳县| 土默特右旗| 张北县|