My bad, I made a mistake while reading and Copy/pasting the code. =p
Two things for that :
First : You create your clock inside the loop, it means at each frames, it is created, queried then destroyed. Just write your sf::Clock Timer; outside the loop. (just before the sf::RenderWindow). When you create your clock, the creation's time is stored somewhere, it mean it is Reset() automaticaly at the creation. =p
Second : the while(App.GetEven(Event)) is used to retrieve ALL the Events that have been received during the frame, it is to be used only with the Events, nothing else. You should try your Timer after retrieving all the events.
Your code become something like this :
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
////////////////////////////////////////////////////////////
int main()
{
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
sf::Clock Timer; // Our timer, self-initializing
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
if (Timer.GetElapsedTime() >= 3) // Quering the timer for the time
App.Close();
// Display window contents on screen
App.Clear();
App.Display();
}
return EXIT_SUCCESS;
}
Also, the application take some time to create the window, the timer start after the window is created. It mean the 3 secondes are the time while the window is displaying something. If you really want your program to last 3 seconde with the window creation time, juste initialize your timer before you create your window :
sf::Clock Timer;
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
A simple way to do things properly :
- Declaring and initializing objets
- starting the game loop
- Retrieve and manage events
- Do all the calculation stuff (query timers, manage and move objects with the result of the previous events, ...)
- Draw the scene (after it is fully and clearly calculated.)