Method: Ruby2D::Canvas#initialize

Defined in:
lib/ruby2d/canvas.rb

#initialize(width:, height:, x: 0, y: 0, z: 0, rotate: 0, fill: [0, 0, 0, 0], color: nil, colour: nil, opacity: nil, update: true, show: true) ⇒ Canvas

Create a Canvas.

Parameters:

  • width (Numeric)

    The width of the canvas in pixels

  • height (Numeric)

    The height of the canvas in pixels

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

    Angle, default is 0

  • fill (String) (defaults to: [0, 0, 0, 0])

    Colour to clear the canvas, respects transparency

  • color (String) (defaults to: nil)

    or colour Tint the texture when rendering

  • opacity (Numeric) (defaults to: nil)

    Opacity of the texture when rendering

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

    If true updates the texture for every draw/fill call

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

    If true the canvas is added to Window automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby2d/canvas.rb', line 31

def initialize(width:, height:, x: 0, y: 0, z: 0, rotate: 0,
               fill: [0, 0, 0, 0], color: nil, colour: nil, opacity: nil,
               update: true, show: true)
  @x = x
  @y = y
  @z = z
  @width = width
  @height = height
  @rotate = rotate
  @fill = Color.new(fill)
  self.color = color || colour || 'white'
  color.opacity = opacity if opacity
  @update = update

  ext_create([@width, @height, @fill.r, @fill.g, @fill.b, @fill.a]) # sets @ext_pixel_data
  @texture = Texture.new(@ext_pixel_data, @width, @height)
  add if show
end