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

Author Topic: Poll Events  (Read 1491 times)

0 Members and 1 Guest are viewing this topic.

mjtilbrook1

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Poll Events
« on: November 20, 2016, 02:57:32 pm »
Hi guys, can someone please explain to me as simply as you can how pollEvents work, im struggling to understand them, like, i get the rest of the code, just not the pollEvent part

thanks



while (gameWindow.isOpen())
   {
      sf::Event event;

      while (gameWindow.pollEvent(event))
      {
         if (event.type == sf::Event::Closed)
            gameWindow.close();
      }

   
      gameWindow.display();
   }

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Poll Events
« Reply #1 on: November 20, 2016, 03:30:58 pm »
Events are stored in a (hidden) list when triggered.
pollEvent removes an event from this list and initializes its sf::Event argument with it, and returns false if the list is empty and true otherwise.
Since you call pollevent as the condition of a while loop, it processes every events in the list until it's empty.
« Last Edit: November 20, 2016, 03:32:38 pm by G. »

mjtilbrook1

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Poll Events
« Reply #2 on: November 20, 2016, 03:46:43 pm »
thanks i guess that makes sense, thats helped me out a bit, some things are just hard to understand haha  :P

 

anything