Class: Engine::Components::SpriteRenderer

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/sprite_renderer.rb

Instance Attribute Summary collapse

Attributes inherited from Engine::Component

#game_object

Instance Method Summary collapse

Methods inherited from Engine::Component

#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #set_game_object, #ui_renderer?

Constructor Details

#initialize(tl, tr, br, bl, texture, frame_coords = nil, frame_rate = nil, loop = true, colour = { r: 1, g: 1, b: 1.0 }) ⇒ SpriteRenderer

Returns a new instance of SpriteRenderer.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/engine/components/sprite_renderer.rb', line 12

def initialize(tl, tr, br, bl, texture, frame_coords = nil, frame_rate = nil, loop = true, colour = { r: 1, g: 1, b: 1.0 })
  @v1 = tl
  @v2 = tr
  @v3 = br
  @v4 = bl
  @texture = texture
  @colour = colour
  @frame_coords = frame_coords || [{ tl: Vector[0, 0], width: 1, height: 1 }]
  @frame_rate = frame_rate || 1
  @loop = loop
end

Instance Attribute Details

#colourObject

Returns the value of attribute colour.



6
7
8
# File 'lib/engine/components/sprite_renderer.rb', line 6

def colour
  @colour
end

#frame_coordsObject (readonly)

Returns the value of attribute frame_coords.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def frame_coords
  @frame_coords
end

#frame_rateObject (readonly)

Returns the value of attribute frame_rate.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def frame_rate
  @frame_rate
end

#loopObject (readonly)

Returns the value of attribute loop.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def loop
  @loop
end

#textureObject (readonly)

Returns the value of attribute texture.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def texture
  @texture
end

#v1Object (readonly)

Returns the value of attribute v1.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def v1
  @v1
end

#v2Object (readonly)

Returns the value of attribute v2.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def v2
  @v2
end

#v3Object (readonly)

Returns the value of attribute v3.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def v3
  @v3
end

#v4Object (readonly)

Returns the value of attribute v4.



5
6
7
# File 'lib/engine/components/sprite_renderer.rb', line 5

def v4
  @v4
end

Instance Method Details

#renderer?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/engine/components/sprite_renderer.rb', line 8

def renderer?
  true
end

#startObject



24
25
26
27
28
29
30
# File 'lib/engine/components/sprite_renderer.rb', line 24

def start
  @start_time = Time.now

  setup_vertex_attribute_buffer
  setup_vertex_buffer
  setup_index_buffer
end

#update(delta_time) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/engine/components/sprite_renderer.rb', line 32

def update(delta_time)
  shader.use
  GL.BindVertexArray(@vao)
  GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo)

  set_shader_per_frame_data

  GL.DrawElements(GL::TRIANGLES, 6, GL::UNSIGNED_INT, 0)
  GL.BindVertexArray(0)
  GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0)
end