Class Rubygame::Events::JoystickAxisMoved
In: lib/rubygame/events/joystick_events.rb
Parent: Object

JoystickAxisMoved is an event that occurs when a joystick’s control stick has changed position on one of its axes.

A joystick axis measures the movement of the control stick. Most joysticks have at least 2 axes for each stick, one for horizontal movement, and one for vertical movement. Fancy ones have a third axis for measuring twist, and controllers with two sticks have at least 4 axes.

Unlike simple buttons or keys, which have only 2 values (pressed or not-pressed), a joystick axis has a smooth spectrum of possible values, ranging from -1.0 to 1.0. This allows for smoother, more precise control than is possible with the keyboard.

Methods

new  

Attributes

axis  [R] 
joystick_id  [R] 
value  [R] 

Public Class methods

Creates a new JoystickAxisMoved instance.

joystick_id:an integer identifying which joystick changed. The first joystick is 0.
axis:an integer identifying which axis changed. The first axis on each joystick is 0.
value:a Float representing the current value of the axis. Ranges from -1.0 to 1.0.

[Source]

# File lib/rubygame/events/joystick_events.rb, line 61
      def initialize( joystick_id, axis, value )

        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 axis.kind_of?(Fixnum) and axis >= 0
          raise ArgumentError, "axis must be an integer >= 0"
        end

        @axis = axis

        unless value.kind_of?(Numeric) and value.between?(-1.0, 1.0)
          raise ArgumentError, "value must be a number in the range (-1.0)..(1.0)"
        end

        @value = value.to_f

     end

[Validate]