1
General / Multiple Events Running At the Same Time?
« on: December 15, 2011, 11:49:25 pm »Quote from: "Contadotempo"
What's wrong with using if? Unless you meant else if?
Suppose the user pressed two keys very fast, faster than one frame. If you use if to check new events, this way:
Code: [Select]
while (running)
{
sf::Event event;
if (window.GetEvent(event))
{
// Process event here
}
// Drawing here
window.Display();
}
You will get only one event per frame. There will be a delay of one frame between the time when the user pressed the second key and the time when the program process it. If you use while:
Code: [Select]
while (running)
{
sf::Event event;
while (window.GetEvent(event))
{
// Process event here
}
// Drawing here
window.Display();
}
All available events will be processed every frame. No event will remains to be processed by the next frame. This is the right way.