Class: Ruby2D::Text
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#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
-
#initialize(text, opts = {}) ⇒ Text
constructor
A new instance of Text.
Methods included from Renderable
#a, #a=, #add, #b, #b=, #contains?, #g, #g=, #opacity, #opacity=, #r, #r=, #remove
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 26 27 |
# 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 self.color = opts[:color] || 'white' self.opacity = opts[:opacity] if opts[:opacity] @font = opts[:font] || Font.default unless File.exist? @font raise Error, "Cannot find font file `#{@font}`" end unless ext_init raise Error, "Text `#{@text}` cannot be created" end 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 |
#font ⇒ Object (readonly)
Returns the value of attribute font.
7 8 9 |
# File 'lib/ruby2d/text.rb', line 7 def font @font 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.
8 9 10 |
# File 'lib/ruby2d/text.rb', line 8 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
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby2d/text.rb', line 34 def draw(opts = {}) opts[:rotate] = opts[:rotate] || @rotate unless opts[:color] opts[:color] = [1.0, 1.0, 1.0, 1.0] end self.class.ext_draw([ self, opts[:x], opts[:y], opts[:rotate], opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3] ]) end |