How to create a timer in my games in cocos2dx using C ++

I develop games and run into the problem of creating a timer. I need logic, since time should start from 60 seconds, when it reaches 0, it should end. I am new to this platform.

+6
source share
1 answer

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

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

in this case, it calls "Game: UpdateTimer" once per second. In the update timer, you simply decrease the counter by one, and when it reaches zero, stop the timer as follows:

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

and add a method called

 void Game::UpdateTimer(float dt) { } 
+12
source

All Articles