Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Joystick only reads xbox controllers and no other types  (Read 2287 times)

0 Members and 1 Guest are viewing this topic.

ytivarg

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::Joystick only reads xbox controllers and no other types
« on: November 14, 2017, 03:49:21 pm »
I wanted to try to get everything controller-related working with SFML before trying my luck with xinput, but the title says the problem.  I have an xbox one controller, a steel series controller, and 2 logitec gamepads.  The only one that SFML can read for me is the xbox one controller. 

while (window.isOpen())
        {
                //get player pressing escape to close the game
                if (Keyboard::isKeyPressed(Keyboard::Escape) || sf::Joystick::isButtonPressed(0, 2))
                {
                        window.close();
                }
                window.clear();//clears the window to draw the next frame
                sf::Joystick::update();
                window.display();
        }

Just trying to see if "x" is pressed on the controller to close the window (still learning everything).  No problems with the xbox controller and nothing happens with the other ones. 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11008
    • View Profile
    • development blog
    • Email
Re: sf::Joystick only reads xbox controllers and no other types
« Reply #1 on: November 14, 2017, 05:07:12 pm »
Maybe first check if you get a controller connected. The button layout isn't the same for all controllers, so your hard-coded value might not be the x button.

With xinput don't you get support for only xbox controllers?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ytivarg

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Joystick only reads xbox controllers and no other types
« Reply #2 on: November 14, 2017, 05:44:51 pm »
Thanks for the response.  In my experience, all standard controllers have had the same numbering system for the buttons, except for a generic 5$ one i got from china.  Used to do it on pygame no problem never had an issue with that.  I did end up finding a really well built xinput class and have gotten it to work with every controller I have.   It was daunting at first because that was my first c++ experience with classes and it took a lot of trial and error getting it to work, but it all works perfectly now.  Still curious as to what might fix the issue with SFML, but now that I got it working with xinput i'm finally moving on with the game coding udemy class I'm taking. 

This link is where I found the class I'm using.  Took a bit to fully figure it out but it works perfectly. 
https://www.codeproject.com/Articles/26949/Xbox-Controller-Input-in-C-with-XInput
« Last Edit: November 14, 2017, 05:46:58 pm by ytivarg »

ytivarg

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Joystick only reads xbox controllers and no other types
« Reply #3 on: November 14, 2017, 06:10:45 pm »
Also I did press every button on the controllers before to test them. 

 

anything