Class: Rubygame::Events::JoystickAxisMoved

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygame/events/joystick_events.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(joystick_id, axis, value) ⇒ JoystickAxisMoved

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.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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

Instance Attribute Details

#axisObject (readonly)

Returns the value of attribute axis.



48
49
50
# File 'lib/rubygame/events/joystick_events.rb', line 48

def axis
  @axis
end

#joystick_idObject (readonly)

Returns the value of attribute joystick_id.



47
48
49
# File 'lib/rubygame/events/joystick_events.rb', line 47

def joystick_id
  @joystick_id
end

#valueObject (readonly)

Returns the value of attribute value.



49
50
51
# File 'lib/rubygame/events/joystick_events.rb', line 49

def value
  @value
end