Hey guys, i'm writing a little snake game to get acquainted with SFML 2.1, Thor, and some of the new c++11 features.
I'm having some trouble getting a thor::CallbackTimer to fire. The timer is counting down, being updated every frame, and the connection is valid, but the callbacks aren't being called when the timer expires.
This is how i'm connecting the callback. In the documentation of Thor it looked like it needed a thor::CallbackTimer parameter, but that didn't solve the problem.
mSpecialFoodTimer.connect(std::bind(&Snake::setUpSpecialFood, this));
This is very similar to what is in the examples for Thor, yet it doesn't fire either.
mSpecialFoodTimer.connect(std::bind(&sf::RectangleShape::setFillColor, &gameBoard, sf::Color::Blue));
I also tried it by just putting a lambda statement in there, same behavior. (i'm not sure if this would work in the first place, no compile errors though.)
connect = mSpecialFoodTimer.connect([this] (thor::CallbackTimer & timer) -> void
{
std::cout << "food timer called\n";
food new_food;
sf::Vector2i pos = this->getOpenPosition();
new_food.mapPos = pos;
new_food.type = (thor::random(0,1) == 0 ? FOOD_TYPE::GRAPE : FOOD_TYPE::ORANGE);
mFood.push_back(new_food);
});
Any help would be appreciated !
Are you sure you call update() every frame (see documentation (http://www.bromeon.ch/libraries/thor/v2.0/doc/classthor_1_1_callback_timer.html))? The timer is initialized with a time bigger than zero and runs initially?
Does the following example work, i.e. "expired" is written on the console every second?
#include <Thor/Time/CallbackTimer.hpp>
#include <iostream>
void listener(thor::CallbackTimer& trigger)
{
std::cout << "expired" << std::endl;
trigger.restart(sf::seconds(1.f));
}
int main()
{
thor::CallbackTimer timer;
timer.connect(&listener);
timer.restart(sf::seconds(1.f));
for (;;)
timer.update();
}
If it doesn't work, can you reproduce your problem in a different minimal complete example (http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368)?