Class: Rubygame::Events::JoystickBallMoved

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

Overview

JoystickBallMoved is an event that occurs when a joystick’s trackball has changed position.

A joystick trackball is a ball which rotates freely in a socket, controlled by the user’s fingers or thumb.

A trackball reports movement on x and y axes, measured in pixels, just like a mouse does. However, a trackball does not report its current position, only its movement since the previous event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(joystick_id, ball, rel) ⇒ JoystickBallMoved

Creates a new JoystickBallMoved instance.

joystick_id

an integer identifying which joystick changed. The first joystick is 0.

ball

an integer identifying which ball changed. The first ball on each joystick is 0.

rel

relative position (how much the ball moved since the previous event). [x,y], in pixels.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/rubygame/events/joystick_events.rb', line 209

def initialize( joystick_id, ball, rel )

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

  @ball = ball

  @rel = rel.to_ary.dup
  @rel.freeze

  unless @rel.length == 2
    raise ArgumentError, "rel must have exactly 2 parts (got %s)"%@rel.length
  end

end

Instance Attribute Details

#ballObject (readonly)

Returns the value of attribute ball.



196
197
198
# File 'lib/rubygame/events/joystick_events.rb', line 196

def ball
  @ball
end

#joystick_idObject (readonly)

Returns the value of attribute joystick_id.



195
196
197
# File 'lib/rubygame/events/joystick_events.rb', line 195

def joystick_id
  @joystick_id
end

#relObject (readonly)

Returns the value of attribute rel.



197
198
199
# File 'lib/rubygame/events/joystick_events.rb', line 197

def rel
  @rel
end