Rect

Type    

class (base classes :

[gd]

Inheritance

Rect ⟶ ShapeDisplay ⟶ Object

[bg]

Overview

Creates rectangle shape.


See also 

Display



Overview


  Creates a rectangle shape.


  Rect class inherits Display class, therefore all the methods defined in Display class can also be used in the Rect object.



Syntax



local r = Rect(width, height [, option] )


    • width - (required) width of rectangle

    • height - height of rectangle (if omitted, it is set as the width given)

    • option - (optional) table of extra parameters

     {

        strokeWidth = n,  -- (optional) set width of stroke (default:0)

        strokeColor = color, -- (optional) set stroke color as Color object (default:Color.WHITE)

        fill = color  -- (optional) set fill color as Color object (default:Color.WHITE)

    }


  Note that the initial anchor point is the center of the rectangle.

  Note also that if the alpha of fillcolor is 0, hollow rectangle will be drawn.


Methods


methods inheritted from Shape class :

method

description

return

obj:setStrokeWidth(n)

set width of outline

self

obj:setStrokeColor(color)

set color of outline with Color object

self

obj:fill(color)

set color of inner area with Color object

self

obj:empty()

display stroke only

self


Rect class methods :

method

description

return

obj:setWidth(n)

reset the width of the rectangle as n

self

obj:setHeight(n)

reset the height of the rectangle as n

self

obj:getWidth()

get width of the rectangle

number

obj:getHeight()

get height of the rectangle

number



Examples



local rect1 = Rect(100,200,{fill=Color(255,0,0)})

-- or

local rect1 = Rect(100,200):fill(Color(255,0,0))



local rect2 = Rect(200,50,{strokeWidth=20, strokeColor=Color.RED})


-- later, change the fillcolor of rect2

rect2:fill(Color.BLUE)


댓글 없음:

댓글 쓰기