Earlier I successfully managed to adapt my stab at Conway's Game of Life to SFML and it runs perfectly, but I'm in the process of expanding it and the first thing I wanted to do was to display a timer in the upper left corner of the screen. My idea was to have a function like this:
void timer(sf::RenderWindow& rw, sf::String& str){
sf::Clock c;
float t;
while (isRunning == true){
t = c.GetElapsedTime();
c.Reset();
std::stringstream ss;
ss << t;
std::string elapsedTime = ss.str();
str.SetText(elapsedTime);
rw.Draw(str);
}
}
(which looks pretty good, I'm still new to SFML so if this looks weird please say so)
However it makes no sense to get the elapsed time each game cycle so I decided to put it in a separate thread so that it can evenly increment the time and display it independently from the game itself. It gives me a error when I try to do this however:
//Create new thread
sf::Thread thread(&timer, mw, time);
thread.Launch();
Error log:
||=== Game of Life, Debug ===|
C:\Game of Life\main.cpp||In function 'int main()':|
C:\Game of Life\main.cpp|65|error: no matching function for call to 'sf::Thread::Thread(void (*)(sf::RenderWindow&, sf::String&), sf::RenderWindow&, sf::String&)'|
C:\Users\Gylfi\Documents\SFML\SFML-1.6\include\SFML\System\Win32\Thread.hpp|92|note: candidates are: sf::Thread::Thread()|
C:\Users\Gylfi\Documents\SFML\SFML-1.6\include\SFML\System\Win32\Thread.hpp|57|note: sf::Thread::Thread(void (*)(void*), void*)|
C:\Users\Gylfi\Documents\SFML\SFML-1.6\include\SFML\System\Win32\Thread.hpp|45|note: sf::Thread::Thread(const sf::Thread&)|
||=== Build finished: 1 errors, 0 warnings ===|
The tutorial says you can pass in the parameters the threaded function needs but it is not working. How do you go about passing in a function that takes parameters into sf::Thread objects?