SFML community forums
Help => Window => Topic started by: reDo on June 30, 2011, 08:08:56 pm
-
I use Escape as exit in main menu and also as return from sub menu, I tried to make blocking loop when Escape is pressed for a little time like few seconds or more that only return to menu and no close all program.
Here is my code, I tried to change it many times but it doesnt work good.
Please give me addvice if you can. :roll:
This is my waiting code with mentioned blocking loop after draw score in the display.
while(1)
{
sf::Event Event;
App.GetEvent(Event);
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
sf::Event Event;
App.GetEvent(Event);
while(App.GetInput().IsKeyDown(sf::Key::Escape))
{
sf::Event Event;
App.GetEvent(Event);
sf::Sleep(0.05);
}
break;
}
if(Event.Type == sf::Event::Closed)
return -1;
sf::Sleep(0.05);
}
-
Sorry its credits function :) , complete code
int cCredits::Draw(sf::RenderWindow & App)
{
App.Clear();
sf::String author;
author.SetSize(50);
author.SetText("Combat Shooter v1.0");
author.SetPosition(50,0);
author.SetColor(sf::Color(218,255,127));
App.Draw(author);
author.SetSize(30);
author.SetText("Programming, menu: reDo");
author.SetPosition(30,100);
author.SetColor(sf::Color(165,255,127));
App.Draw(author);
author.SetText("Designer: KalliSSimo ");
author.SetPosition(60,140);
author.SetColor(sf::Color(127,255,197));
App.Draw(author);
App.Display();
while(1)
{
sf::Event Event;
App.GetEvent(Event);
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
sf::Event Event;
App.GetEvent(Event);
while(App.GetInput().IsKeyDown(sf::Key::Escape))
{
sf::Event Event;
App.GetEvent(Event);
sf::Sleep(0.05);
}
break;
}
if(Event.Type == sf::Event::Closed)
return -1;
sf::Sleep(0.05);
}
return 1;
}
-
You shouldn't use sf::Input, rather check for sf::Event::KeyPressed events. These events occur only once.
And
sf::Event event;
App.GetEvent(Event);
is meaningless. Event handling may only be done once each frame, consider the SFML tutorials to find out how it works.