Genera un nuevo objeto Joystick.
Genera un nuevo objeto Joystick.
pygame.joystick.Joystick(id): return Joystick
Genera un nuevo objeto Joystick para acceder al dispositivo físico. El
argumento id
debe ser un valor de 0 a pygame.joystick.get_count() -1
.
Necesita llamar al método init() del Joystick para acceder
a la mayoría de los métodos del Joystick. Este método está separado
de ello para asegurarse que se inicializa el módulo joystick. El estado y
valores para los objetos Joystick se puede compartir cuando se generan
múltiples objetos Joystick a partir del mismo dispositivo (por ejemplo, si
tienen el mismo identificador ID
).
El objeto Joystick le permite obtener información acerca de los controles en el dispositivo de Joystick. La cola de eventos comenzará a recibir eventos de esta entrada una vez que el dispositivo esté inicializado.
Puede llamar a las funciones Joystick.get_name()
y Joystick.get_id()
sin inicializar el objeto Joystick.
Inicializa el Joystick.
Joystick.init(): return None
El Joystick se debe inicializar para obtener la mayor información acerca de los controles. Cuando el Joystick se inicializa la cola de eventos de pygame recibirá la entrada de comandos del Joystick.
Es seguro llamar a este método mas de una vez.
Deshabilita el Joystick.
Joystick.quit(): return None
Este método deshabilita el Joystick. Después de esto, la cola de eventos de pygame no recibirá mas eventos del dispositivo.
Es seguro llamar a esta función mas de una vez.
Consulta si el Joystick está incializado.
Joystick.get_init(): return bool
Retorna True
si ya se ha llamado al método init() en
este objeto.
Obtiene el identificador del Joystick.
Joystick.get_id(): return int
Retorna en número identificador que representa este dispositivo. Este valor es el mismo que se ha indicado al constructor del Joystick(). Este método se puede llamar de forma segura mientras el Joystick no esté inicializado.
Obtiene el nombre de sistema del Joystick.
Joystick.get_name(): return string
Retorna el nombre de sistema para este dispositivo de Joystick. Se desconoce que nombre dará el sistema al Joystick, aunque debería ser un nombre único que identifica al dispositivo. Este método se puede llamar con seguridad mientras el Joystick no esté inicializado.
Retorna el número de mandos de posición de un joystick.
Joystick.get_numaxes(): return int
Retorna el número de mandos de posición de un Joystick. Generalmente será de mandos para la posición (horizontal y vertical). Controles como aletas de avión o frenos se manejan como mandos de posición adicionales.
Los eventos pygame.JOYAXISMOTION irán en el rango de -1.0 a 1.0. Un valor como 0.0 significa que el eje está centrado. Los joysticks tradicionales generalmente informan -1, 0 o 1 pero sin valores intermedios. Y los joysticks analógicos antiguos no siempre utilizan el rango de -1 a 1 completo, y el centro es un valor cercano a 0. Estos joysticks antiguos también suelen tener un poco de ruido en los ejes, lo que generará un montón de eventos de movimiento rápidos.
Obtiene la posición actual de un eje.
Joystick.get_axis(axis_number): return float
Retorna la posición actual de un eje del joystick. El valor estará en el rango que va de -1 a 1 con un valor de 0 como centro. Tal vez deba tener en cuenta cierta toleracia a las imperfecciones de estos valores.
El número de eje debe ser un entero de cero a get_numaxes() -1
.
Obtiene el número de ejes en un joystick.
Joystick.get_numballs(): return int
Returns the number of trackball devices on a Joystick. These devices work similar to a mouse but they have no absolute position; they only have relative amounts of movement.
The pygame.JOYBALLMOTION event will be sent when the trackball is rolled. It will report the amount of movement on the trackball.
get the relative position of a trackball
Joystick.get_ball(ball_number): return x, y
Returns the relative movement of a joystick button. The value is a x, y pair holding the relative movement since the last call to get_ball.
The ball number must be an integer from zero to get_numballs() -1
.
get the number of buttons on a Joystick
Joystick.get_numbuttons(): return int
Returns the number of pushable buttons on the joystick. These buttons have a boolean (on or off) state.
Buttons generate a pygame.JOYBUTTONDOWN and pygame.JOYBUTTONUP event when they are pressed and released.
get the current button state
Joystick.get_button(button): return bool
Returns the current state of a joystick button.
get the number of hat controls on a Joystick
Joystick.get_numhats(): return int
Returns the number of joystick hats on a Joystick. Hat devices are like miniature digital joysticks on a joystick. Each hat has two axes of input.
The pygame.JOYHATMOTION event is generated when the hat changes position. The position attribute for the event contains a pair of values that are either -1, 0, or 1. A position of (0, 0) means the hat is centered.
get the position of a joystick hat
Joystick.get_hat(hat_number): return x, y
Returns the current position of a position hat. The position is given as two values representing the X and Y position for the hat. (0, 0) means centered. A value of -1 means left/down and a value of 1 means right/up: so (-1, 0) means left; (1, 0) means right; (0, 1) means up; (1, 1) means upper-right; etc.
This value is digital, i.e., each coordinate can be -1, 0 or 1 but never in-between.
The hat number must be between 0 and get_numhats() -1
.