Class: Ruby2D::Text
Overview
Text string drawn using the specified font and size
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
Class Method Summary collapse
-
.create_texture(text, size: 20, style: nil, font: Font.default) ⇒ Object
Create a texture for the specified text.
Instance Method Summary collapse
- #draw(x:, y:, color:, rotate:) ⇒ Object
-
#font ⇒ Object
Returns the path of the font as a string.
-
#initialize(text, size: 20, style: nil, font: Font.default, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) ⇒ Text
constructor
Create a text string.
Methods included from Renderable
Constructor Details
#initialize(text, size: 20, style: nil, font: Font.default, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) ⇒ Text
Create a text string
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruby2d/text.rb', line 25 def initialize(text, size: 20, style: nil, font: Font.default, x: 0, y: 0, z: 0, rotate: 0, color: nil, colour: nil, opacity: nil, show: true) @x = x @y = y @z = z @text = text.to_s @size = size @rotate = rotate @style = style self.color = color || colour || 'white' self.color.opacity = opacity unless opacity.nil? @font_path = font @texture = nil create_font create_texture add if show end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/ruby2d/text.rb', line 11 def data @data end |
#rotate ⇒ Object
Returns the value of attribute rotate.
11 12 13 |
# File 'lib/ruby2d/text.rb', line 11 def rotate @rotate end |
#size ⇒ Object
Returns the value of attribute size.
10 11 12 |
# File 'lib/ruby2d/text.rb', line 10 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
10 11 12 |
# File 'lib/ruby2d/text.rb', line 10 def text @text end |
#x ⇒ Object
Returns the value of attribute x.
11 12 13 |
# File 'lib/ruby2d/text.rb', line 11 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
11 12 13 |
# File 'lib/ruby2d/text.rb', line 11 def y @y end |
Class Method Details
.create_texture(text, size: 20, style: nil, font: Font.default) ⇒ Object
Create a texture for the specified text
77 78 79 80 |
# File 'lib/ruby2d/text.rb', line 77 def create_texture(text, size: 20, style: nil, font: Font.default) font = Font.load(font, size, style) Texture.new(*Text.ext_load_text(font.ttf_font, text)) end |
Instance Method Details
#draw(x:, y:, color:, rotate:) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/ruby2d/text.rb', line 62 def draw(x:, y:, color:, rotate:) Window.render_ready_check x ||= @rotate color ||= [1.0, 1.0, 1.0, 1.0] render(x: x, y: y, color: Color.new(color), rotate: rotate) end |
#font ⇒ Object
Returns the path of the font as a string
47 48 49 |
# File 'lib/ruby2d/text.rb', line 47 def font @font_path end |