Class: Ruby2D::Text

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/ruby2d/text.rb

Instance Attribute Summary collapse

Attributes included from Renderable

#color, #height, #width, #z

Instance Method Summary collapse

Methods included from Renderable

#add, #contains?, #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
# 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

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def data
  @data
end

#rotateObject

Returns the value of attribute rotate.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def rotate
  @rotate
end

#sizeObject

Returns the value of attribute size.



7
8
9
# File 'lib/ruby2d/text.rb', line 7

def size
  @size
end

#textObject

Returns the value of attribute text.



7
8
9
# File 'lib/ruby2d/text.rb', line 7

def text
  @text
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/ruby2d/text.rb', line 8

def x
  @x
end

#yObject

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

#fontObject

Returns the path of the font as a string



28
29
30
# File 'lib/ruby2d/text.rb', line 28

def font
  @font_path
end