Class: Engine::Components::UI::SpriteRenderer

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/ui/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, #renderer?, #set_game_object, #update

Methods included from Serializable

allowed_class?, #awake, get_class, included, register_class, #uuid

Instance Attribute Details

#materialObject (readonly)

Returns the value of attribute material.



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

def material
  @material
end

Instance Method Details

#drawObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/engine/components/ui/sprite_renderer.rb', line 24

def draw
  rect = @ui_rect.computed_rect

  Engine::GL.BindVertexArray(@vao)
  Engine::GL.BindBuffer(Engine::GL::ELEMENT_ARRAY_BUFFER, @ebo)

  update_vertex_buffer(rect)
  set_material_per_frame_data

  Engine::GL.DrawElements(Engine::GL::TRIANGLES, 6, Engine::GL::UNSIGNED_INT, 0)
end

#startObject



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

def start
  @ui_rect = game_object.component(UI::Rect)
  raise "UI::SpriteRenderer requires a UI::Rect component on the same GameObject" unless @ui_rect

  setup_vertex_attribute_buffer
  setup_index_buffer
  setup_vertex_buffer
  Engine::GL.BindVertexArray(0)
end

#ui_renderer?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/engine/components/ui/sprite_renderer.rb', line 10

def ui_renderer?
  true
end