Class: Ruby2D::Rectangle
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes inherited from Quad
#c1, #c2, #c3, #c4, #color, #x1, #x2, #x3, #x4, #y1, #y2, #y3, #y4
Attributes included from Renderable
Instance Method Summary collapse
- #contains?(x, y) ⇒ Boolean
-
#initialize(opts = {}) ⇒ Rectangle
constructor
A new instance of Rectangle.
Methods inherited from Quad
Methods included from Renderable
#add, #opacity, #opacity=, #remove
Constructor Details
#initialize(opts = {}) ⇒ Rectangle
Returns a new instance of Rectangle.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ruby2d/rectangle.rb', line 8 def initialize(opts = {}) @x = opts[:x] || 0 @y = opts[:y] || 0 @z = opts[:z] || 0 @width = opts[:width] || 200 @height = opts[:height] || 100 update_coords(@x, @y, @width, @height) self.color = opts[:color] || 'white' add end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
6 7 8 |
# File 'lib/ruby2d/rectangle.rb', line 6 def height @height end |
#width ⇒ Object
Returns the value of attribute width.
6 7 8 |
# File 'lib/ruby2d/rectangle.rb', line 6 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/ruby2d/rectangle.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/ruby2d/rectangle.rb', line 6 def y @y end |
Instance Method Details
#contains?(x, y) ⇒ Boolean
45 46 47 |
# File 'lib/ruby2d/rectangle.rb', line 45 def contains?(x, y) @x < x and @x + @width > x and @y < y and @y + @height > y end |