1
Graphics / Re: App freezes after few seconds
« on: June 03, 2020, 11:09:43 am »void Game::GameLoop()
{
sf::Event currentEvent;
while(mainWindow.pollEvent(currentEvent))
{
if (currentEvent.type == sf::Event::Closed)
mainWindow.close();
switch(gameState)
{
case Game::ShowingMenu:
{
ShowMenu();
break;
}
case Game::ShowingSplash:
{
ShowSplashScreen();
break;
}
case Game::Playing:
{
while(gameState!=ShowingMenu)
{
mainWindow.clear(sf::Color(80,70,200));
player1.Draw(mainWindow);
mainWindow.display();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
ShowMenu();
gameState = ShowingMenu;
cout << 1;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
player1.mirror(false);
mainWindow.clear(sf::Color(80,70,200));
player1.moving(-2,0);
player1.Draw(mainWindow);
mainWindow.display();
cout << 2;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
player1.mirror(true);
mainWindow.clear(sf::Color(80,70,200));
player1.moving(2,0);
player1.Draw(mainWindow);
mainWindow.display();
cout << 3;
}
}
if(currentEvent.type == sf::Event::Closed)
gameState=Game::Exiting;
}
}
}
}
{
sf::Event currentEvent;
while(mainWindow.pollEvent(currentEvent))
{
if (currentEvent.type == sf::Event::Closed)
mainWindow.close();
switch(gameState)
{
case Game::ShowingMenu:
{
ShowMenu();
break;
}
case Game::ShowingSplash:
{
ShowSplashScreen();
break;
}
case Game::Playing:
{
while(gameState!=ShowingMenu)
{
mainWindow.clear(sf::Color(80,70,200));
player1.Draw(mainWindow);
mainWindow.display();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
ShowMenu();
gameState = ShowingMenu;
cout << 1;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
player1.mirror(false);
mainWindow.clear(sf::Color(80,70,200));
player1.moving(-2,0);
player1.Draw(mainWindow);
mainWindow.display();
cout << 2;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
player1.mirror(true);
mainWindow.clear(sf::Color(80,70,200));
player1.moving(2,0);
player1.Draw(mainWindow);
mainWindow.display();
cout << 3;
}
}
if(currentEvent.type == sf::Event::Closed)
gameState=Game::Exiting;
}
}
}
}