Hey guys, i have the following code:
Code:
bool QueryNewGame(ConfigFile &pConfig, sf::RenderWindow *pApp)
{
pApp->Clear();
sf::Font GUIFont;
if( !GUIFont.LoadFromFile(pConfig.read<std::string>("gui_font"))) return false;
sf::String Str("", GUIFont, pConfig.read<int>("gui_text_size"));
sf::Event Event;
time_t StartTime = time(NULL);
int EndTime = pConfig.read<int>("game_continue_timer");
while( difftime(time(NULL), StartTime ) < EndTime )
{
int ElapsedTime = difftime(time(NULL), StartTime);
std::stringstream SS;
SS << "PRESS SPACE TO RESTART THE GAME, PRESS ESCAPE TO EXIT.\n" << ElapsedTime;
Str.SetText(SS.str().c_str());
Str.SetColor(sf::Color(255, 0, 0));
SS.str("");
Str.Move(pApp->GetWidth()/10, pApp->GetHeight()/2);
sf::Event Event;
pApp->GetEvent(Event);
//Window closed
if(Event.Type == sf::Event::Closed)
return false;
//Escape pressed
if( (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape) )
return false;
if( (Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space) )
return true;
pApp->Draw(Str);
pApp->Display();
}
return false;
}
Which *should* output the text string to the screen, along with the elapsed time in seconds. For some reason the elapsed time that reaches the screen is always 0. I have run this through GDB and the ElapsedTime variable gets incremented properly, with the amount of seconds since the start of the function. GDB won't let me look into the stringstream however, for some reason it's just an "unknown type" so i suspect that is where the problem is, am i using this stringstream all wrong?