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

Author Topic: No sf::Input without checking for Events?  (Read 6801 times)

0 Members and 1 Guest are viewing this topic.

BorisDieKlinge

  • Newbie
  • *
  • Posts: 15
    • View Profile
No sf::Input without checking for Events?
« on: June 24, 2009, 10:39:17 pm »
Hallo world :]

I just started out with SFML. On my way I had a problem. I'm sure you can help me ;-)

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(600,300),"test");

    sf::Image Image;
    Image.LoadFromFile("lol.JPG");
    const sf::Input& Input = App.GetInput();

    sf::Sprite Sprite(Image);

    sf::Event Event;

    while (App.IsOpened())
    {
/*
      while (App.GetEvent(Event))
        {
            if (Event.Type==sf::Event::Closed)
              App.Close();

            if ((Event.Type==sf::Event::KeyPressed) && (Event.Key.Code==sf::Key::D))
              Sprite.Move(1.5,0);
        }
*/

bool Rechts = Input.IsKeyDown(sf::Key::Right);
    if(Rechts)
      Sprite.Move(1.5,0);
        App.Clear(sf::Color(231,32,111));
        App.Draw(Sprite);
        App.Display();
    }
    return 0;
}


I comiles and it runs but it doesn't do what I expact it to do.
It doesn't react if I prss the Right key.

How ever...when I also compile the comments ( between /*  */) it works.
Why? IsKeyDown doesn't depend on GetEvent does it?

BorisDieKlinge

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
No sf::Input without checking for Events?
« Reply #1 on: June 24, 2009, 10:50:07 pm »
You have to call GetEvent to use sf::Input. This will be different with the upcoming version 2.
SFML / OS X developer

BorisDieKlinge

  • Newbie
  • *
  • Posts: 15
    • View Profile
No sf::Input without checking for Events?
« Reply #2 on: June 24, 2009, 11:27:50 pm »
Thank you.

 

anything