Class: Ruby2D::Texture

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/texture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pixel_data, width, height) ⇒ Texture

Returns a new instance of Texture.



7
8
9
10
11
12
# File 'lib/ruby2d/texture.rb', line 7

def initialize(pixel_data, width, height)
  @pixel_data = pixel_data
  @width = width
  @height = height
  @texture_id = 0
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/ruby2d/texture.rb', line 5

def height
  @height
end

#texture_idObject (readonly)

Returns the value of attribute texture_id.



5
6
7
# File 'lib/ruby2d/texture.rb', line 5

def texture_id
  @texture_id
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/ruby2d/texture.rb', line 5

def width
  @width
end

Instance Method Details

#deleteObject



24
25
26
# File 'lib/ruby2d/texture.rb', line 24

def delete
  ext_delete(@texture_id)
end

#draw(coordinates, texture_coordinates, color) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ruby2d/texture.rb', line 14

def draw(coordinates, texture_coordinates, color)
  if @texture_id == 0
    @texture_id = ext_create(@pixel_data, @width, @height)
    @pixel_data = nil
  end

  color = [color.r, color.g, color.b, color.a]
  ext_draw(coordinates, texture_coordinates, color, @texture_id)
end