SFML community forums
General => SFML projects => Topic started by: Guido_Ion on October 09, 2021, 12:12:19 am
-
Hi guys I wanted to share this class that I made that uses SDL's controller database (https://github.com/gabomdq/SDL_GameControllerDB). I started looking for a gamepad db for SFML and I noticed that it is a common request from users so I decided to do it myself.
https://github.com/GuidoBisocoli/SFML_GamepadSupport (https://github.com/GuidoBisocoli/SFML_GamepadSupport)
Features:
- It supports Left and Right Trigger as button or axis seamlessly
- It manages inverted axes
TO DO:
- Support for dpad
- Hide buttons, axes and triggers, now they are public
- Read also linux and MacOs gamepads
- Test gamepads
I've only tested it with my 2 gamepads (Logitech Dual Action and Controller (XBOX 360 For Windows)) and it works great, if you can help testing other gamepads please comment and let us know.
-
Oh, this is really cool to see.
Yes, it's been something that quite a few people have requested and/or thought about doing.
Would be awesome if you could put it somewhere on GitHub/GitLab and add a license, so it can be more easily shared and contributed to, plus the license makes it possible to use it (I recommend MIT or similar permissive license).
-
Uploaded!
https://github.com/GuidoBisocoli/SFML_GamepadSupport (https://github.com/GuidoBisocoli/SFML_GamepadSupport)
I added XInput support and other things, still some things to do and also check more gamepads. MIT license :)
-
Added support for events with the method "getButtonNumber(GAMEPAD_BUTTON btn)"
if (_currentEvent.type == sf::Event::EventType::JoystickButtonReleased && _currentEvent.joystickButton.joystickId == 0 && _currentEvent.joystickButton.button == _gamepadOne->getButtonNumber(Gamepad::GAMEPAD_BUTTON::btn_start))
/// do something
This is to avoid checking many times the same button.
-
Update:
- XInput gamepad number is not always the same as the number provided by sf::Joystick, this is determined and handled properly by the Gamepad Manager.
This was an issue when connecting an XInput Gamepad and another not XInput Gamepad and the number assigned by XInput (always 0 if there is only one connected) didn't match the number provided by sf::Joystick which can be 0 or 1.
For this I added a Gamepad Manager that takes care of initializing and populating every Gamepad whether it is XInput or other and regardless of whether the XInput number matches or not the one provided by sf::Joystick.