You can use Joystick.activate_all to start receiving events for all joysticks (equivalent to creating them all individually with Joystick.new). You can use Joystick.deactivate_all to stop receiving events for all joysticks.
These old Joystick-related events are deprecated and will be removed in Rubygame 3.0:
For more information about “new-style” events, see EventQueue.enable_new_style_events.
|Returns:||Array of zero or more Joysticks.|
|May raise:||SDLError, if the joystick system could not be initialized.|
# File lib/rubygame/joystick.rb, line 82 def self.activate_all # Initialize if it isn't already. if( SDL.WasInit(SDL::INIT_JOYSTICK) == 0 ) if( SDL.Init(SDL::INIT_JOYSTICK) != 0 ) raise Rubygame::SDLError, "Could not initialize SDL joysticks." end end # Collect Joystick instances in an Array joysticks =  num_joysticks.times do |i| joysticks << new( i ) end return joysticks end
Deactivate all joysticks on the system. This will stop all joystick-related events from being sent to the EventQueue.
# File lib/rubygame/joystick.rb, line 104 def self.deactivate_all # Return right away if it isn't active return if( SDL.WasInit(SDL::INIT_JOYSTICK) == 0 ) num_joysticks.times do |i| joy = SDL.JoystickOpen(i) unless( joy.pointer.nil? ) SDL.JoystickClose( joy ) end end return nil end
Create and initialize an interface to the Nth joystick on the system. Raises SDLError if the joystick could not be opened.
# File lib/rubygame/joystick.rb, line 122 def initialize( index ) @struct = SDL.JoystickOpen( index ) if( @struct.pointer.null? ) raise( Rubygame::SDLError, "Could not open joystick %d: %s"% [index, SDL.GetError()] ) end end
Returns the total number of joysticks detected on the system.
# File lib/rubygame/joystick.rb, line 60 def self.num_joysticks SDL.NumJoysticks() end
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.
# File lib/rubygame/joystick.rb, line 153 def axes SDL.JoystickNumAxes( @struct ) end