SFML community forums
Help => Window => Topic started by: fabvman on October 21, 2010, 04:31:32 pm
-
Hi everyone. I have a little problem. I was reading the tutorials and I want to move a sprite on the screen using the gamepad, but I don't understand how to use joystick input (buffered or unbuffered), I mean, how to take and do something with I trigger some event. Can you give me some orientation about using class input and event?. Thanks!
-
Hi fabvman.
Gamepad input is handled in the exact same way keyboard input is.
const sf::Input& Input = App.GetInput();
if(Input.IsJoystickButtonDown(0, 1))
{
//do something
}
if(Input.GetJoystickAxis(0, sf::Joy::AxisX < -0.5))
{
//move my guy left
}
All you have to keep in mind is the first argument for isJoyStickButtonDown() and GetJoyStickAxis() is the controller number. The second argument is which button/axis you are trying to test.
-
Thanks Epaik, that helps me a lot. But I don't understand why you put < -0.5 as a second parameter of getjoyaxis()
-
He just forgot a closing parenthesis after "sf::Joy::AxisX".
-
He just forgot a closing parenthesis after "sf::Joy::AxisX".
Good catch.
Thanks Epaik, that helps me a lot. But I don't understand why you put < -0.5 as a second parameter of getjoyaxis()
The reason I did -0.5 is the getjoyaxis function returns an approximate float value for each axis. For example, for a gamepad the x-axis might be ~-1.0 for left, ~0 for nothing pressed, ~1.0 for right.