Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been using SFML 1.6 for a while and recently upgraded to 2.0, apparently there's a new sf::Time type however I'm clueless as to how I can achieve running of a certain function after a set amount of time.

How would you go about doing this? Say you want something to execute after 5 seconds, how would you do it in SFML?

share|improve this question
up vote 3 down vote accepted

SFML provides a delta time function.

sf::Clock deltaClock;
for (;;)
    // ...
    sf::Time dt = deltaClock.Restart();

from :

Time class:

Basically what you could do is create a class that holds pointers to functions you want to call. And for each function you have a "clock" ( a simple float or int ) in a time table(Array/Vector) that is iterated over in combination with the delta time to see if x amount of seconds have passed. If so you do a callback on the associated function.

I'm not that much deep into C++ and there is probably a clever way to do it. There is also this :

Which is build ontop of SFML but it requires C++11. It's an unofficial extension library that has some great event triggering functionality.

On the upside of C++11, it supports "function" objects. Which help ease out some function referencing.

Also google for events and C++ if you really want to dive deep into it.

share|improve this answer
Thanks That should help. – Bugster Oct 5 '12 at 9:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.