How to create timer in my games in cocos2dx using c++ [closed]
Asked Answered
P

1

7

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.

Positivism answered 13/5, 2014 at 6:13 Comment(3)
google search, my friend -> cocos2d-x.org/forums/6/topics/12050?r=12053Astyanax
There are a number of ways to create timers and times events, maybe std::thread and writing a Timer class. I usually create a std::vector of std::threads and they all run at their proper intervals and I can get to them easily to manipulate. If you accepted more answers people provide they might give you more help.Imp
I found this thread. iphonedevsdk.com/forum/iphone-sdk-development/… I tried, couldn't get it to work, but might help someone :-) Myself will try to sort it out using schedule like the accepted answer.Tact
E
14

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)
{

}
Eicher answered 14/5, 2014 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.