I’ve been reading the SDL tutorials and I was wondering how I would be
able to handle multiple axis events, like if a controller had a left
analog stick and a right analog stick, would the right analog stick’s
axis, be “event.jaxis.axis == 5”?.
Please log in or register to post a reply.
to get the number of axes available on the device, and then call
to get the position of the axis you want.
EDIT: It sounds like you are using SDL_JoyAxisEvent. In that case, the
axis field does indeed contain the index of the axis in which motion was
Thanks, do you know how I would be able to detect if the button was
pressed at the same time as the stick?, just do
“ case SDL_JOYAXISMOTION && SDL_JOYBUTTONDOWN: “
I think you want a single & there, not a double &&.
Oh, what’s the difference?, is a single & C where a double and is
I use C++ so it should work fine. But if does’nt I’ll try a single
Actually, never mind what I said. The SDL_Event structure is a
discriminated union, so you’ll never get more than one event type at the
same time. If you want to test that the user pushes the button and moves
the stick in a certain time frame, you’ll have to do it yourself.
(By the way, it has nothing to do with C vs C++. Single & is a bitwise
op, double && is a logical op. In this case, I thought you were looking
at a bitfield, so the bitwise op would be the appropriate one to use.)
Oh, thanks for the help, I’ll have a bool variable, that is set to true
when a button is pressed and then reset, I’ll also try something similar
for the analog.
Right, you will have to track the state of the buttons as you receive
button up/down events and then check the stored button state when you
receive axis events. Alternatively, you can turn-off joystick events and
poll the state of the joystick as needed.