1
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .