Question

I am developing games and facing problem with creating timer. I need some logic like time should start from 60 sec when it reach to 0 game should end. I am new to this platform.

Was it helpful?

Solution

I usually use the scheduler for this, which you can use to call a method at fixed time intervals, like this:

this->schedule(schedule_selector(Game::UpdateTimer),1.0f);

in this case it calls 'Game:UpdateTimer' once a second. In update timer you'd just reduce your counter by one, and when it's reach zero stop the timer like this:

this->unschedule( schedule_selector(Game::UpdateTimer));

and add a method underneath to be called

void Game::UpdateTimer(float dt)
{

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top