Class Rubygame::Joystick
In: ext/rubygame/rubygame_event.c
Parent: Object

The Joystick class interfaces with joysticks, gamepads, and other similar hardware devices, commonly used to play games. Each joystick can offer 0 or more axes, balls, hats, and/or buttons.

After a Joystick object is successfully created, events for that Joystick will begin appearing on the Queue, reporting any state change that occurs. Some examples of state changes are a button being pressed or released, or a control stick being moved (resulting in one or more axes being changed).

The full list of Joystick-related events is as follows:

In future versions of Rubygame, it will be possible to directly query the state each joystick. However, it is recommended that you use the event system for most cases, so you might as well get used to it!

Methods

axes   balls   buttons   get_name   hats   index   name   new   num_joysticks  

Public Class methods

Returns the name of nth joystick on the system, up to 1024 characters long. The name is implementation-dependent. See also name().

Create and initialize an interface to the nth joystick on the system. Raises SDLError if the joystick could not be opened.

Returns the total number of joysticks detected on the system.

Public Instance methods

Returns the number of axes (singular: axis) featured on the Joystick. Each control stick generally has two axes (X and Y), although there are other types of controls which are represented as one or more axes. See also axis_state().

Returns the number of trackballs featured on the Joystick. A trackball is usually a small sphere which can be rotated in-place in any direction, registering relative movement along two axes. See alse ball_state().

Returns the number of buttons featured on the Joystick. A button can be in one of two states: neutral, or pushed. See also button_state()

Returns the number of hats featured on the Joystick. A hat is a switch which can be pushed in one of several directions, or centered. See also hat_state().

Returns the index number of the Joystick, i.e. the identifier number of the joystick that this interface controls. This is the same number that was given to new().

Returns a String containing the name of the Joystick, up to 1024 characters long. The name is implementation-dependent. See also get_name().

[Validate]