Class: Ruby2D::Text
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#rotate ⇒ Object
Returns the value of attribute rotate.
-
#size ⇒ Object
Returns the value of attribute size.
-
#text ⇒ Object
Returns the value of attribute text.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes included from Renderable
Instance Method Summary collapse
- #draw(opts = {}) ⇒ Object
-
#font ⇒ Object
Returns the path of the font as a string.
-
#initialize(text, opts = {}) ⇒ Text
constructor
A new instance of Text.
Methods included from Renderable
Constructor Details
#initialize(text, opts = {}) ⇒ Text
Returns a new instance of Text.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby2d/text.rb', line 10 def initialize(text, opts = {}) @x = opts[:x] || 0 @y = opts[:y] || 0 @z = opts[:z] || 0 @text = text.to_s @size = opts[:size] || 20 @rotate = opts[:rotate] || 0 @style = opts[:style] self.color = opts[:color] || 'white' self.color.opacity = opts[:opacity] if opts[:opacity] @font_path = opts[:font] || Font.default create_font create_texture unless opts[:show] == false then add end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def data @data end |
#rotate ⇒ Object
Returns the value of attribute rotate.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def rotate @rotate end |
#size ⇒ Object
Returns the value of attribute size.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def text @text end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 def y @y end |
Instance Method Details
#draw(opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby2d/text.rb', line 43 def draw(opts = {}) Window.render_ready_check opts[:rotate] = opts[:rotate] || @rotate unless opts[:color] opts[:color] = [1.0, 1.0, 1.0, 1.0] end render(x: opts[:x], y: opts[:y], color: Color.new(opts[:color]), rotate: opts[:rotate]) end |
#font ⇒ Object
Returns the path of the font as a string
28 29 30 |
# File 'lib/ruby2d/text.rb', line 28 def font @font_path end |