Class: Rubygame::EventTriggers::MousePressTrigger
- Inherits:
-
Object
- Object
- Rubygame::EventTriggers::MousePressTrigger
- Defined in:
- lib/rubygame/event_triggers.rb
Overview
MousePressTrigger is an event trigger which fires when a mouse button is pressed down (i.e. MousePressed).
By default, this trigger fires for any mouse press, but it can be configured to fire for only a specific mouse button by passing a button symbol to #new.
See also MousReleaseTrigger.
Instance Method Summary collapse
-
#initialize(button = :any) ⇒ MousePressTrigger
constructor
Initialize a new instance of MousePressTrigger with the given mouse button.
-
#match?(event) ⇒ Boolean
Returns true if the event is a MousePressed event and the event’s button is the same as the trigger’s button (or the trigger’s button is :any).
Constructor Details
#initialize(button = :any) ⇒ MousePressTrigger
Initialize a new instance of MousePressTrigger with the given mouse button.
- button
-
The mouse button symbol to detect, or :any to detect any button press.
Valid mouse button symbols are: :mouse_left, :mouse_middle, :mouse_right, :mouse_wheel_up, and :mouse_wheel_down.
525 526 527 |
# File 'lib/rubygame/event_triggers.rb', line 525 def initialize( =:any ) @button = end |
Instance Method Details
#match?(event) ⇒ Boolean
Returns true if the event is a MousePressed event and the event’s button is the same as the trigger’s button (or the trigger’s button is :any).
533 534 535 536 537 538 539 |
# File 'lib/rubygame/event_triggers.rb', line 533 def match?( event ) if event.kind_of?( Rubygame::Events::MousePressed ) ((@button == :any) or (event. == @button)) else false end end |