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

Author Topic: Wired controllers "Joystick 0 is NOT connected" but input still accepted  (Read 3592 times)

0 Members and 1 Guest are viewing this topic.

DCurro

  • Newbie
  • *
  • Posts: 5
    • View Profile
This occurs on both OSX, and Windows.  It occurs for both wired XBox360 and wired Logitech Dual Action.

if(sf::Joystick::isConnected(0)){
        std::cout << "Joystick 0 is connected" << std::endl;
} else {
        std::cout << "Joystick 0 is NOT connected" << std::endl;
}

returns "Joystick 0 is NOT connected".

But, input for the first controller is still accepted, just as normal.  Wireless controllers are recognized properly, though.

DCurro

  • Newbie
  • *
  • Posts: 5
    • View Profile
I moved this query to after the RenderWindow was created, and it reports proper connection.  I will do further testing, with multiple controllers, on multiple platforms.

EDIT: The CORRECT solution is stated below, by Laurent.
« Last Edit: May 05, 2014, 08:22:03 am by DCurro »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Have you read the big red box at the end of the joystick tutorial?

Quote
Joystick states are automatically updated by the event loop. If you don't have one, or need to read a joystick state (for example, check which joysticks are connected) before starting your game loop, you'll have to call the sf::Joystick::update() function to make sure that the joystick states are up to date.
Laurent Gomila - SFML developer

DCurro

  • Newbie
  • *
  • Posts: 5
    • View Profile
I read the joystick tutorial from top to bottom last week, when I implemented it.  Never need to call update.  Guess it caught up to me.

Thank you very much Laurent, that answers my question perfectly!

 

anything