Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 down vote accepted

SFML provides a delta time function.

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

from : http://en.sfml-dev.org/forums/index.php?topic=7068.0

Time class:
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Time.php

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 : http://www.bromeon.ch/libraries/thor/

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
add comment

Your Answer

 
discard

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.