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

Author Topic: SFML Ping Pong  (Read 4048 times)

0 Members and 1 Guest are viewing this topic.

faizaanceg

  • Newbie
  • *
  • Posts: 3
  • Working at TechLucia
    • View Profile
    • TechLucia
    • Email
SFML Ping Pong
« on: May 16, 2014, 01:57:09 pm »
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 ?
SFML for the win !

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: SFML Ping Pong
« Reply #1 on: May 16, 2014, 02:18:58 pm »
Welcome to the forums!

If your first button contains the position, then your "else if" has no effect.
However we can't help any further, because we don't know how you implemented these buttons.
You could either give us some more information, or give a complete and minimal example.

The commented region is where the problem is, [...]
There is no commented region btw.

Edit: This should also not be under "SFML Projects", better under "General" or the corresponding sfml-module :)
« Last Edit: May 16, 2014, 02:21:21 pm by Geheim »
Failing to succeed does not mean failing to progress!

faizaanceg

  • Newbie
  • *
  • Posts: 3
  • Working at TechLucia
    • View Profile
    • TechLucia
    • Email
Re: SFML Ping Pong
« Reply #2 on: May 16, 2014, 03:23:14 pm »
Hmm, sorry for the incomplete details.

Here is the GitHub link : https://github.com/faizaanceg/Ping-pong

In the handle_input function,(ping.h) is the part I posted before.

SFML for the win !

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: SFML Ping Pong
« Reply #3 on: May 16, 2014, 03:46:19 pm »
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.

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!
Failing to succeed does not mean failing to progress!

faizaanceg

  • Newbie
  • *
  • Posts: 3
  • Working at TechLucia
    • View Profile
    • TechLucia
    • Email
Re: SFML Ping Pong
« Reply #4 on: May 16, 2014, 04:10:27 pm »
WOW.Oh My God ! I wanna hang myself -_- That was the error. (Man...) Thanks very much for that and really sorry for such a stupid mistake :/
SFML for the win !

jannugimes

  • Guest
Re: SFML Ping Pong
« Reply #5 on: May 16, 2014, 06:15:50 pm »
No [problem man
WOW.Oh My God ! I wanna hang myself -_- That was the error. (Man...) Thanks very much for that and really sorry for such a stupid mistake :/
No problem man.

 

anything