Method: Ruby2D::Text#initialize

Defined in:
lib/ruby2d/text.rb

#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

Parameters:

  • text

    The text to show

  • size (Numeric) (defaults to: 20)

    The font size

  • font (String) (defaults to: Font.default)

    Path to font file to use to draw the text

  • style (String) (defaults to: nil)

    Font style

  • x (Numeric) (defaults to: 0)
  • y (Numeric) (defaults to: 0)
  • z (Numeric) (defaults to: 0)
  • rotate (Numeric) (defaults to: 0)

    Angle, default is 0

  • color (Numeric) (defaults to: nil)

    or colour Colour the text when rendering

  • opacity (Numeric) (defaults to: nil)

    Opacity of the image when rendering

  • show (true, false) (defaults to: true)

    If true the Text is added to Window automatically.



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