3dmodelerman at October 19th, 2008 16:47 — #1
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 left/right (X/Y)
axis, be "event.jaxis.axis == 5"?.
monjardin at October 19th, 2008 19:32 — #2
You use SDL_JoystickNumAxes to get the number of axes available on the device, and then call SDL_JoystickGetAxis 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 detected.
3dmodelerman at October 20th, 2008 10:05 — #3
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: "
reedbeta at October 20th, 2008 12:06 — #4
I think you want a single & there, not a double &&.
3dmodelerman at October 20th, 2008 13:41 — #5
Oh, what's the difference?, is a single & C where a double and is C++?.
I use C++ so it should work fine. But if does'nt I'll try a single one.
reedbeta at October 20th, 2008 13:55 — #6
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.)
3dmodelerman at October 20th, 2008 20:06 — #7
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.
monjardin at October 21st, 2008 10:19 — #8
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.