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

Author Topic: Real-Time Input in SFML 2  (Read 4897 times)

0 Members and 3 Guests are viewing this topic.

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Real-Time Input in SFML 2
« on: June 08, 2012, 04:50:18 pm »
Hello,

How can I move my sprite smoothly since Input is no longer in SFML 2.0?

I've tried to do it this way but it still isn't smooth and there's a "pause" when I press arrow (probably because of those "xx = false" at bot.. but I have no idea how to do that

        while(MainWindow.isOpen())
        {
                Event Event;
                while(MainWindow.pollEvent(Event))
                {
                        if(Event.type == Event::Closed)
                                MainWindow.close();
                        if(Keyboard::isKeyPressed(Keyboard::Left))
                        {
                                left = true;
                        }
                        if(Keyboard::isKeyPressed(Keyboard::Right))
                        {
                                right = true;
                        }
                        if(Keyboard::isKeyPressed(Keyboard::Up))
                        {
                                up = true;
                        }
                        if(Keyboard::isKeyPressed(Keyboard::Down))
                        {
                                down = true;
                        }
                        if(left)
                                sT.move(-5, 0);
                        if(right)
                                sT.move(5, 0);
                        if(up)
                                sT.move(0, -5);
                        if(down)
                                sT.move(0, 5);
                }

                left = false;
                right = false;
                up = false;
                down = false;

                MainWindow.clear();

                MainWindow.draw(sBackground);

                MainWindow.draw(sT);

                MainWindow.display();
        }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Real-Time Input in SFML 2
« Reply #1 on: June 08, 2012, 05:54:15 pm »
Your logic doesn't make sense. Why do you query the keyboard state inside an event loop?
Laurent Gomila - SFML developer

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Real-Time Input in SFML 2
« Reply #2 on: June 08, 2012, 06:03:11 pm »
Your logic doesn't make sense. Why do you query the keyboard state inside an event loop?

uhm, idk? I remember that it was event in 1.6 :D anyway thanks :D it's working

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Real-Time Input in SFML 2
« Reply #3 on: June 08, 2012, 06:08:16 pm »
No, your code would have the same problem with SFML 1.6 :P
Laurent Gomila - SFML developer

 

anything