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

Author Topic: Window.pollEvent() problems  (Read 7002 times)

0 Members and 1 Guest are viewing this topic.

KarmaKilledtheCat

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Window.pollEvent() problems
« on: August 28, 2013, 04:39:57 pm »
I am making a game with sfml but have run into a problem. Whenever the program gets to the Window.pollEvent() function it stops until I give the program some kind of event(keyboard press, mouse movement, mouse clicks, ect.). Does anybody know how to make the program keep running even if it isn't receiving an event?

This is my main loop where the problem is:
//SFML libraries
#include <SFML/Graphics.hpp>

//Faster files
#include "globals.h"
#include "ScreenManager.h"

int main()
{
        sf::RenderWindow Window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "Faster"); //create the window
        Window.setFramerateLimit(60); //set the frame limit to 60

        ScreenManager::GetInstance().Initialize(); //Initialize the screen manager
        ScreenManager::GetInstance().Load(); //load the splash screen from the screen manager

        while (Window.isOpen()) //while the window is opened
        {
                sf::Event Event;
                while (Window.pollEvent(Event)) //the game loop
                {
                        if (Event.type == sf::Event::Closed) //if the close button is hit
                                Window.close(); //close the window

                        ScreenManager::GetInstance().Update(Window, Event); //update the screen manager
                        ScreenManager::GetInstance().Draw(Window); //draw the screen

                        Window.display(); //display the window
                        Window.clear(); //clear the window
                }
        }
}
 

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Window.pollEvent() problems
« Reply #1 on: August 28, 2013, 04:48:36 pm »
while (Window.pollEvent(Event)) //the game loop
It's NOT the game loop, it's the event loop, where you're supposed to process events, and you enter it only when an event is triggered.
Don't put your draw, clear and display inside it. Take a look at the tutorials for examples. (first piece of code here)
« Last Edit: August 28, 2013, 04:51:20 pm by G. »

KarmaKilledtheCat

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Window.pollEvent() problems
« Reply #2 on: August 28, 2013, 04:53:43 pm »
That worked thanks for the help.

 

anything