When I press any button or stick on the gamepad, I get several sf::Event::JoystickMoved events.
I think it's axis calibration issue...
Check out what you get with this program (don't press any axes. Just press any button).
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "");
window.setVerticalSyncEnabled(true);
sf::Joystick::update();
std::vector<std::string> names = {
"X", ///< The X axis
"Y", ///< The Y axis
"Z", ///< The Z axis
"R", ///< The R axis
"U", ///< The U axis
"V", ///< The V axis
"PovX", ///< The X axis of the point-of-view hat
"PovY" ///< The Y axis of the point-of-view hat
};
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::JoystickMoved:
std::cout << names[event.joystickMove.axis] << " " << event.joystickMove.position << std::endl;
break;
default:
break;
}
}
window.clear(); // fill background with color
window.display();
}
}
I consistently get this:
X 0.389105
Y -1.17952
R -395209
U 4.31067
What can I do about it?
Have you checked with something else than SFML, to make sure that this is not a driver or hardware issue?
You should also test other gamepads, and/or on other OSes.
Yes, I checked with Windows 7 and Windows 8. Gamepads: Xbox 360 gamepad and Logitech F310. The output I included in the original post was from Logitech F310.
Xbox 360 gamepad gives me this:
X -5.18044
Y 6.1387
R 4.53651
U -4.19776
Even if it's hardware issue (calibration being not perfect), maybe SFML should do something with it? Like checking initial state of buttons and then checking new position of axes from it? It looks like this causes the problem. SFML assumes that all axes are at 0 by default, but they may be a little off. It sees that axis has different value than 0, thinking that it has moved a bit.
I think that's what happens. Other button pressed don't produce wrong events.