I recently got into SFML and have played around with it quite a bit. I have noticed however that in all my tests there has been some kind of stutter. I was previously unable to figure out what caused it until I by chance commented out the while-loop which calls mWindow.pollEvent(). I first thought it was the way I was achieving a fixed timestep, but changing between an alternating and a fixed timestep did not have any effect on the stutter, or at least not as much as pollEvent() seems to have.
I am slightly suspicious though, considering I have looked far and wide for solutions and come up with close to nothing relating to specifically pollEvent. Here's a video demonstrating the issue.
https://www.youtube.com/watch?v=wrsGuczoIxQ&feature=youtu.beAny ideas?
In case it's relevant, I use
Windows 7 Ultimate,
a 3,10 GHz 8-Core AMD,
8GB RAM
and a NVIDIA GeForce GTX 660Ti
// Starts the game loop
void Game::run()
{
sf::Clock gameTime;
const float TimePerFrame = 1.f / 60.f;
float elapsedTime = 0;
while (mWindow.isOpen())
{
elapsedTime += gameTime.restart().asSeconds();
while (elapsedTime > TimePerFrame)
{
elapsedTime -= TimePerFrame;
handleEvents();
update(TimePerFrame);
}
draw();
}
}
// Checks for and handles events
void Game::handleEvents()
{
sf::Event event;
while (mWindow.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
mWindow.close();
break;
}
}
}