Hello, I'm not really good at coding, so please explain more understandable.
I wanted to create something like a pause for a game and came up with this idea:
int main()
{
//RenderWindow
bool pause = false;
game:
while ((window.isOpen()) && (!pause))
{
float time = time = clock.getElapsedTime().asMicroseconds();
clock.restart();
time = time / gameSpeed;
sf::Event event;
while ((window.pollEvent(event)) && (!pause))
{
if (event.type == sf::Event::Closed)
{
window.close();
return 1;
}
if ((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Esc))
{
pause = true;
}
}...
//game body//
}
while ((window.isOpen()) && (pause))
{
sf::Event event;
while ((window.pollEvent(event)) && (pause))
{
if (event.type == sf::Event::Closed)
{
window.close();
return 1;
}
if ((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Esc))
{
pause = false;
goto game;
}
}
window.display();
}
}
The problem is that it doesn't work very well. The game becomes a bit lagging, I mean the animations start to flicker and finally, when I go back to game:, the player falls through the map, nevertheless every loop is in the first while.
What should I do?