Class: Engine::Components::UISpriteClickbox
- Inherits:
-
Engine::Component
- Object
- Engine::Component
- Engine::Components::UISpriteClickbox
- Defined in:
- lib/engine/components/ui_sprite_clickbox.rb
Instance Attribute Summary collapse
-
#clicked ⇒ Object
readonly
Returns the value of attribute clicked.
-
#mouse_entered ⇒ Object
readonly
Returns the value of attribute mouse_entered.
-
#mouse_exited ⇒ Object
readonly
Returns the value of attribute mouse_exited.
-
#mouse_inside ⇒ Object
readonly
Returns the value of attribute mouse_inside.
Attributes inherited from Engine::Component
Instance Method Summary collapse
-
#initialize ⇒ UISpriteClickbox
constructor
A new instance of UISpriteClickbox.
- #start ⇒ Object
- #update(delta_time) ⇒ Object
Methods inherited from Engine::Component
#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #ui_renderer?
Constructor Details
#initialize ⇒ UISpriteClickbox
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
#clicked ⇒ Object (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_entered ⇒ Object (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_exited ⇒ Object (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_inside ⇒ Object (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
#start ⇒ Object
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 |