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

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
主站蜘蛛池模板: 万全县| 神池县| 陆丰市| 全南县| 义乌市| 洪洞县| 榆社县| 琼中| 得荣县| 桑植县| 长乐市| 太仆寺旗| 报价| 奎屯市| 泸西县| 婺源县| 和林格尔县| 长沙县| 武安市| 吴江市| 平和县| 尉氏县| 宁远县| 苍梧县| 蒲城县| 伊金霍洛旗| 泰州市| 信阳市| 武城县| 邹平县| 灵璧县| 保山市| 藁城市| 尼玛县| 吴忠市| 呼图壁县| 翁源县| 穆棱市| 达拉特旗| 炉霍县| 滕州市|