|
Joysticks - How can I get more than one working |
devo_au
Member #15,282
August 2013
|
Hey, I'm making a game that has 2 or more players using gamepads. ALLEGRO_EVENT ev; if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN) {}
that allows me to determine //im using all the init stuff correctly, //this is just a snippit to explain what im up to ALLEGRO_JOYSTICK_STATE joyState1; al_get_joystick_state(joy1, &joyState1); cout << joyState1.button << "\n";
I get the same output from all the main buttons (ie. 00E9A5D8) Hope someone can help - Thanks Dev it wasn't me, it was other kids |
RPG Hacker
Member #12,492
January 2011
|
Have you iterated over all joysticks Allegro returns to you? Maybe it's polling some data from a weird device. Or maybe it's a driver issue of some sorts. As for using ALLEGRO_EVENTs, this page has some more information for you: Or in other words: ev.joystick.id
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Yes, RPG Hacker is correct. Use ev.joystick.id to get the joystick id. And with joystick button events, use ev.joystick.button to get the button pressed. As for al_get_joystick_state, you're not using it correctly. joystick_state.button is an array, not a bool value indicating whether a button was pressed. You need to access the specific button that you are asking for first : for (int i = 0 ; i < al_get_num_joysticks() ; ++i) { ALLEGRO_JOYSTICK* joy = al_get_joystick(i); ALLEGRO_JOYSTICK_STATE joy_state; al_get_joystick_state(joy , &joy_state); for (int j = 0 ; j < al_get_joystick_num_buttons ; ++j) { if (joy_state.button[j]) { printf("Joystick number %d has button %d pressed.\n" , i , j); } } }
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
devo_au
Member #15,282
August 2013
|
Awesome thank you for your replies.. RPG - I didn't know about ev.joystick.id. Iterating them. Hmmm... Thanks for that loop Edgar. So thats what RPG meant. Cheers guys. You have helped me heaps.. Dev it wasn't me, it was other kids |
|