class Rubygame::Events::JoystickHatMoved
JoystickHatMoved is an event that occurs when a joystick's hat switch has changed direction.
A joystick hat switch is a round switch that can be pressed in 8 possible directions: up, down, left, right, or the four diagonal directions. (Some hat switches support extra diagonal directions, but only those 8 directions are supported by Rubygame.)
Attributes
Public Class Methods
Creates a new JoystickHatMoved instance.
- #joystick_id
-
an integer identifying which joystick changed. The first joystick is 0.
- hat
-
an integer identifying which hat switch changed. The first hat switch on each joystick is 0.
- direction
-
a symbol telling the direction the hat switch is being pressed. The direction is either nil or one of these 8 symbols:
:up :up_right :right :down_right :down :down_left :left :up_left
# File lib/rubygame/events/joystick_events.rb, line 285 def initialize( joystick_id, hat, direction ) unless joystick_id.kind_of?(Fixnum) and joystick_id >= 0 raise ArgumentError, "joystick_id must be an integer >= 0" end @joystick_id = joystick_id unless hat.kind_of?(Fixnum) and hat >= 0 raise ArgumentError, "hat must be an integer >= 0" end @hat = hat unless @@direction_map.keys.include? direction raise ArgumentError, "invalid direction '%s'. "%[direction.inspect] + "Check the docs for valid directions." end @direction = direction @horizontal, @vertical = @@direction_map[direction] end
Public Instance Methods
True if the hat is in the center (not pressed in any direction).
# File lib/rubygame/events/joystick_events.rb, line 314 def center? @direction == nil end
True if the hat is pressed down, down-right, or down-left.
# File lib/rubygame/events/joystick_events.rb, line 335 def down? @vertical == 1 end
True if the hat is pressed left, up-left, or down-left.
# File lib/rubygame/events/joystick_events.rb, line 320 def left? @horizontal == -1 end
True if the hat is pressed right, up-right, or down-right.
# File lib/rubygame/events/joystick_events.rb, line 325 def right? @horizontal == 1 end
True if the hat is pressed up, up-right, or up-left.
# File lib/rubygame/events/joystick_events.rb, line 330 def up? @vertical == -1 end