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

Author Topic: Moving joystick counts as a button press...???  (Read 2781 times)

0 Members and 1 Guest are viewing this topic.

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Moving joystick counts as a button press...???
« on: September 15, 2016, 04:21:24 pm »
Disclaimer: I'm using SFML 2.0...

I'm very confused.  I'm trying to implement a way for the player of my game to customize their controls.

Basically, they highlight the action they want to change, let's say, "Jump."  They press A, which indicates that the game should now "listen" for a button press and set whatever button to be the "Jump" button.  Just like any game you've ever played that allowed custom controls.

However, if I set my bool _listening to true and then move the joystick, it's recognizing the joystick having been moved as a "button press" and sets the button value to either 0 for the x axis or 1 for the y axis.

How the heck do I fix this?  I really feel like moving the joystick should not be triggering a button pressed event.  The offending code:

else if (_controlsSetup && _listening)
    {
        // leaving this code here just in case it's a matter
       // of {'s or }'s
        if (event.type == sf::Event::KeyPressed)
        {
            if(event.key.code == sf::Keyboard::Return)
            {
                _keyToStore = "";          // Indicates what action (jump, shoot) the key press is for
                _buttonToStore = "";     // ditto for controller buttons.
                _listening = false;
            }
            else if(_keyboardSettings)
            {
                game()->settings()->keyIs(_keyToStore, event.key.code);
                _keyToStore = "";
                _listening = false;
            }
        }
        if (event.type = sf::Event::JoystickButtonPressed)
        {
            // SOMEHOW we are arriving here despite no buttons being pressed, only the joystick being moved.
            if(_controllerSettings)
            {
                _listening = false;
                game()->settings()->buttonIs(_buttonToStore, event.joystickButton.button);
                _buttonToStore = "";
            }
        }
    }

As always, any help is deeply appreciated.  I imagine it's something dumb but...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Moving joystick counts as a button press...???
« Reply #1 on: September 15, 2016, 04:34:33 pm »
Quote
if (event.type = sf::Event::JoystickButtonPressed)
should be ==
Laurent Gomila - SFML developer

gws923

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: Moving joystick counts as a button press...???
« Reply #2 on: September 15, 2016, 04:47:31 pm »
Quote
if (event.type = sf::Event::JoystickButtonPressed)
should be ==

I actually saw that immediately after posting but couldn't delete the post.  Thanks, though!

 

anything