Class: Engine::Components::SpriteRenderer
- Inherits:
-
Engine::Component
- Object
- Engine::Component
- Engine::Components::SpriteRenderer
- Defined in:
- lib/engine/components/sprite_renderer.rb
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#frame_coords ⇒ Object
readonly
Returns the value of attribute frame_coords.
-
#frame_rate ⇒ Object
readonly
Returns the value of attribute frame_rate.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
-
#texture ⇒ Object
readonly
Returns the value of attribute texture.
-
#v1 ⇒ Object
readonly
Returns the value of attribute v1.
-
#v2 ⇒ Object
readonly
Returns the value of attribute v2.
-
#v3 ⇒ Object
readonly
Returns the value of attribute v3.
-
#v4 ⇒ Object
readonly
Returns the value of attribute v4.
Attributes inherited from Engine::Component
Instance Method Summary collapse
-
#initialize(tl, tr, br, bl, texture, frame_coords = nil, frame_rate = nil, loop = true, colour = { r: 1, g: 1, b: 1.0 }) ⇒ SpriteRenderer
constructor
A new instance of SpriteRenderer.
- #renderer? ⇒ Boolean
- #start ⇒ Object
- #update(delta_time) ⇒ Object
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
#colour ⇒ Object
Returns the value of attribute colour.
6 7 8 |
# File 'lib/engine/components/sprite_renderer.rb', line 6 def colour @colour end |
#frame_coords ⇒ Object (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_rate ⇒ Object (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 |
#loop ⇒ Object (readonly)
Returns the value of attribute loop.
5 6 7 |
# File 'lib/engine/components/sprite_renderer.rb', line 5 def loop @loop end |
#texture ⇒ Object (readonly)
Returns the value of attribute texture.
5 6 7 |
# File 'lib/engine/components/sprite_renderer.rb', line 5 def texture @texture end |
#v1 ⇒ Object (readonly)
Returns the value of attribute v1.
5 6 7 |
# File 'lib/engine/components/sprite_renderer.rb', line 5 def v1 @v1 end |
#v2 ⇒ Object (readonly)
Returns the value of attribute v2.
5 6 7 |
# File 'lib/engine/components/sprite_renderer.rb', line 5 def v2 @v2 end |
#v3 ⇒ Object (readonly)
Returns the value of attribute v3.
5 6 7 |
# File 'lib/engine/components/sprite_renderer.rb', line 5 def v3 @v3 end |
#v4 ⇒ Object (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
8 9 10 |
# File 'lib/engine/components/sprite_renderer.rb', line 8 def renderer? true end |
#start ⇒ Object
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 |