0
\$\begingroup\$

Using SFML, every event type will produce a large negative value for x and y of -858993460.

if (menuEvent.type == sf::Event::GainedFocus 
    || menuEvent.type == sf::Event::LostFocus
    || menuEvent.type == sf::Event::KeyPressed 
    || menuEvent.type == sf::Event::KeyReleased 
    || menuEvent.type == sf::Event::MouseEntered
    || menuEvent.type == sf::Event::MouseMoved
    || menuEvent.type == sf::Event::MouseButtonReleased
    || menuEvent.type == sf::Event::MouseButtonPressed) {

    return HandleFindExit(menuEvent.mouseButton.x, menuEvent.mouseButton.y);
    // Except for when menuEvent.type is MouseButtonReleased 
    // or MouseButtonPressed x and y will be -858993460
}

I am wondering if this is an intended result or am I attempting to use these events incorrectly?

It seems to me there is a use case for knowing the position of the mouse cursor on MouseMoved, for example so you can have a button change to a different sprite as if you are hovering over it.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It would make sense that mouseButton won't have proper values except for events that involve the mouse button - MouseButtonReleased and MouseButtonPressed.

If for example you wanted the mouse position for MouseMoved events, you should be looking at the mouseMove member, which is of type MouseMoveEvent.

Always use the right event data for the event type. A mapping can be found in source code:

  221     union
  222     {
  223         SizeEvent             size;              
  224         KeyEvent              key;               
  225         TextEvent             text;              
  226         MouseMoveEvent        mouseMove;         
  227         MouseButtonEvent      mouseButton;       
  228         MouseWheelEvent       mouseWheel;        
  229         MouseWheelScrollEvent mouseWheelScroll;  
  230         JoystickMoveEvent     joystickMove;      
  231         JoystickButtonEvent   joystickButton;    
  232         JoystickConnectEvent  joystickConnect;   
  233         TouchEvent            touch;             
  234         SensorEvent           sensor;            
  235     };

FYI -858993460 in hexadecimal is CCCCCCCC. It is a garbage value used by microsoft compilers for uninitialised values.

\$\endgroup\$
1
  • \$\begingroup\$ Yep, on any MouseEntered, MouseMoved, MouseButtonReleased, MouseButtonPressed events I can get the x and y from menuEvent.mouseMove.x or y. Thanks. \$\endgroup\$ Commented Feb 19, 2019 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .