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

Author Topic: SFML 2.0 gamepad not detected  (Read 3725 times)

0 Members and 1 Guest are viewing this topic.

lagoru

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
SFML 2.0 gamepad not detected
« on: October 03, 2012, 03:39:25 pm »
Hi, I have a problem with gamepad I want to use with SFML 2.0. Library just can't detect it.
Code used:
if (sf::Joystick::isConnected(0))
        {
            cout << "Is connected " << endl;
        }
        else
        {
            cout << "Not connected" << endl;
        }

I only include SFML/Window/Joystick.hpp. Library looks that is working fine (it detects keyboard).
IDE: QT Creator (MinGW compiler), System: Windows 7
also tried on CODE::BLOCKS.

System detects gamepads (checked in control panel), all buttons and levers work fine.
Gamepads tried: esperanza Warrior, Apollo GP 3020.
« Last Edit: October 03, 2012, 03:48:29 pm by Laurent »

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: SFML 2.0 gamepad not detected
« Reply #1 on: October 03, 2012, 03:42:51 pm »
Maybe try including #include <SFML/Window.hpp> instead of only including Joystick.hpp

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 gamepad not detected
« Reply #2 on: October 03, 2012, 03:44:26 pm »
Then your OS probably doesn't set it to the controller 0, but something else, so you'll have to find out which one is actually connected, e.g.:

for(unsigned int i=0; i< sf::Joystick::Count; ++i)
{
    if(sf::Joystick::isConnected(i))
         std::cout << "Joystick " << i << " is connected!" << std::endl;
    else
         std::cout << "Joystick " << i << " is NOT connected!" << std::endl;
}

Also see the documentation of sf::Joystick for further details.
Please make use of the code=cpp tag in the forum! ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 gamepad not detected
« Reply #3 on: October 03, 2012, 03:52:59 pm »
If you don't have an event loop, you need to call sf::Joystick::update() manually to update the joysticks state.
« Last Edit: October 03, 2012, 04:07:36 pm by Laurent »
Laurent Gomila - SFML developer

lagoru

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: SFML 2.0 gamepad not detected
« Reply #4 on: October 03, 2012, 04:02:15 pm »
Also tried tricks in first and second post before posting - no difference.


The last one helped :) thank you very much :)