### Home Classes Methods

### In Files

- lib/rubygame/events/joystick_events.rb

### Parent

Object

### Methods

- ::new
- #center?
- #down?
- #left?
- #right?
- #up?

### Files

- CREDITS
- LICENSE
- NEWS
- README
- ROADMAP
- custom_sdl_load_paths.rdoc
- getting_started.rdoc
- keyboard_symbols.rdoc
- macosx_install.rdoc
- managing_framerate.rdoc
- surface_palettes.rdoc
- windows_install.rdoc

### Class/Module Index

Quicksearch

- Rubygame
- Rubygame::ActiveEvent
- Rubygame::Clock
- Rubygame::Color
- Rubygame::Color::ColorBase
- Rubygame::Color::ColorHSL
- Rubygame::Color::ColorHSV
- Rubygame::Color::ColorRGB
- Rubygame::Color::Palette
- Rubygame::Event
- Rubygame::EventActions
- Rubygame::EventActions::BlockAction
- Rubygame::EventActions::MethodAction
- Rubygame::EventActions::MultiAction
- Rubygame::EventHandler
- Rubygame::EventHandler::HasEventHandler
- Rubygame::EventHook
- Rubygame::EventQueue
- Rubygame::EventTriggers
- Rubygame::EventTriggers::AndTrigger
- Rubygame::EventTriggers::AttrTrigger
- Rubygame::EventTriggers::BlockTrigger
- Rubygame::EventTriggers::InstanceOfTrigger
- Rubygame::EventTriggers::KeyPressTrigger
- Rubygame::EventTriggers::KeyReleaseTrigger
- Rubygame::EventTriggers::KindOfTrigger
- Rubygame::EventTriggers::MouseMoveTrigger
- Rubygame::EventTriggers::MousePressTrigger
- Rubygame::EventTriggers::MouseReleaseTrigger
- Rubygame::EventTriggers::OrTrigger
- Rubygame::EventTriggers::TickTrigger
- Rubygame::EventTriggers::YesTrigger
- Rubygame::Events
- Rubygame::Events::ClockTicked
- Rubygame::Events::InputFocusGained
- Rubygame::Events::InputFocusLost
- Rubygame::Events::JoystickAxisMoved
- Rubygame::Events::JoystickBallMoved
- Rubygame::Events::JoystickButtonEvent
- Rubygame::Events::JoystickButtonPressed
- Rubygame::Events::JoystickButtonReleased
- Rubygame::Events::JoystickHatMoved
- Rubygame::Events::KeyPressed
- Rubygame::Events::KeyReleased
- Rubygame::Events::KeyboardEvent
- Rubygame::Events::MouseButtonEvent
- Rubygame::Events::MouseFocusGained
- Rubygame::Events::MouseFocusLost
- Rubygame::Events::MouseMoved
- Rubygame::Events::MousePressed
- Rubygame::Events::MouseReleased
- Rubygame::Events::QuitRequested
- Rubygame::Events::WindowExposed
- Rubygame::Events::WindowMinimized
- Rubygame::Events::WindowResized
- Rubygame::Events::WindowUnminimized
- Rubygame::ExposeEvent
- Rubygame::Ftor
- Rubygame::GL
- Rubygame::Hotspot
- Rubygame::JoyAxisEvent
- Rubygame::JoyBallEvent
- Rubygame::JoyDownEvent
- Rubygame::JoyHatEvent
- Rubygame::JoyUpEvent
- Rubygame::Joystick
- Rubygame::Key
- Rubygame::KeyDownEvent
- Rubygame::KeyUpEvent
- Rubygame::MailQueue
- Rubygame::MediaBag
- Rubygame::Mixer
- Rubygame::Mixer::Music
- Rubygame::Mixer::Sample
- Rubygame::Mouse
- Rubygame::MouseDownEvent
- Rubygame::MouseMotionEvent
- Rubygame::MouseUpEvent
- Rubygame::Music
- Rubygame::NamedResource
- Rubygame::NamedResource::NamedResourceClassMethods
- Rubygame::QuitEvent
- Rubygame::Rect
- Rubygame::ResizeEvent
- Rubygame::SDLError
- Rubygame::SFont
- Rubygame::Screen
- Rubygame::Sound
- Rubygame::Sprites
- Rubygame::Sprites::DepthSortGroup
- Rubygame::Sprites::Group
- Rubygame::Sprites::LimitGroup
- Rubygame::Sprites::Sprite
- Rubygame::Sprites::UpdateGroup
- Rubygame::Surface
- Rubygame::TTF

No matching classes.

# 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

direction[R]
hat[R]
horizontal[R]
joystick_id[R]
vertical[R]

### Public Class Methods

new( joystick_id, hat, direction ) click to toggle source

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

center?() click to toggle source

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

down?() click to toggle source

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

left?() click to toggle source

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

right?() click to toggle source

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

up?() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.