Class: Engine::Components::UISpriteClickbox

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/ui_sprite_clickbox.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, #ui_renderer?

Constructor Details

#initializeUISpriteClickbox

Returns a new instance of UISpriteClickbox.



7
8
9
10
11
12
# File 'lib/engine/components/ui_sprite_clickbox.rb', line 7

def initialize
  @mouse_inside = false
  @clicked = false
  @mouse_entered = false
  @mouse_exited = false
end

Instance Attribute Details

#clickedObject (readonly)

Returns the value of attribute clicked.



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

def clicked
  @clicked
end

#mouse_enteredObject (readonly)

Returns the value of attribute mouse_entered.



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

def mouse_entered
  @mouse_entered
end

#mouse_exitedObject (readonly)

Returns the value of attribute mouse_exited.



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

def mouse_exited
  @mouse_exited
end

#mouse_insideObject (readonly)

Returns the value of attribute mouse_inside.



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

def mouse_inside
  @mouse_inside
end

Instance Method Details

#startObject



14
15
16
17
# File 'lib/engine/components/ui_sprite_clickbox.rb', line 14

def start
  @renderer = game_object.ui_renderers.find { |r| r.is_a?(Engine::Components::UISpriteRenderer) }
  raise "UISpriteClickbox requires a UISpriteRenderer" unless @renderer
end

#update(delta_time) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/engine/components/ui_sprite_clickbox.rb', line 19

def update(delta_time)
  mouse_pos = Engine::Input.mouse_pos
  return unless mouse_pos

  if point_inside?(mouse_pos)
    @mouse_entered = !@mouse_inside
    @mouse_inside = true
    @clicked = Engine::Input.key_down?(GLFW::MOUSE_BUTTON_LEFT)
  else
    @mouse_exited = @mouse_inside
    @mouse_inside = false
  end
end