Hey everyone,
So me and my friend are learning SFML (it's fun :p). We have just started with the basics and so we decided to make a simple Ping Pong game to test our skills. We have effectively used most simple features and now we decided to use the sf::Mouse events. Thats where the problem starts.
if(Mouse::isButtonPressed(Mouse::Left))
{
Vector2i position =sf::Mouse::getPosition(*window);
if(Up.contains(position))
playerYvel = -(SLIDER_VEL);
else if(Down.contains(position))
playerYvel = (SLIDER_VEL);
else
playerYvel=0;
}
else
playerYvel = 0;
The commented region is where the problem is, the Down button doesn't work at all. It doesn't get the input at all. Is it because of nested if ?
If you are using events, you have to get them first. You can read a detailed information about how to use events in the tutorial (http://www.sfml-dev.org/tutorials/2.1/window-events.php).
What you use in your code is "real-time input", but as far as I can see, the buttons do not overlap, so it is not a problem with the if-statements.
Your error is a pretty annoying one to find: (ping.h, lines 74-77)
Down.left = 730;
Down.top = 190;
Down.width = 20;
Down.width = 20;
What height does this button have? ;)
Besides, header files should only contain declarations!