Joysticks - How can I get more than one working
I'm making a game that has 2 or more players using gamepads.
I can't find an event
if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
that allows me to determine
what gamepad the button presses are occurring from.
If I use states
I get the same output from all the main buttons (ie. 00E9A5D8)
but for some reason it can read select and the triggers.
Hope someone can help - Thanks Dev
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:
Basically, once you detect a ALLEGRO_EVENT_JOYSTICK_AXIS, ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN or ALLEGRO_EVENT_JOYSTICK_BUTTON_UP event, you can check joystick.id to get the ID of the joystick. I'm not sure if ALLEGRO_EVENT already has a joystick field right away or if you need to cast it to another type, but I'd expect that it just uses a union internally and that it already has the joystick field, so you can just check that.
Or in other words: ev.joystick.id
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 :
Thread #616346. Printed from Allegro.cc
Awesome thank you for your replies..
RPG - I didn't know about ev.joystick.id. Iterating them. Hmmm...
Edgar - Ah! that hex number is an address of a array.
Thanks for that loop Edgar. So thats what RPG meant.
Plugged it in - problem solved. Just have to hook it
up to my players.
Cheers guys. You have helped me heaps.. Dev