# Using Timers

## Recommended Posts

Hi Everyone, I've been learning SDL using both LazyFoo's tutorials as well as a nice reference book I bought. One thing I really like about SDL is the getticks() function and how easy LazyFoo made it to understand framerate regulation using this and a Timer class. A couple of questions for those of you who are familiar with his tutorials. If not please see them here (Specifically 12-14). http://lazyfoo.net/SDL_tutorials/index.php My question is regarding the pause(), unpause(), and stop() member functions of the Timer class. Basically, I'm trying to fully understand why I would need these in my game. I assume the pause() and unpause() would be for doing exactly that...pausing the game :P. The stop() function I would guess could be when you die and have to restart so it needs to reset the startTicks and framecount in your Timer. But, lets assume that my game is extremely simple (which it will be considering its my first). The game starts and there is one linear objective such as Tetris with no option to pause the game. When you lose, the game simply quits and exits the program. In this situation, wouldn't I only really need to start the timer(get the ticks at the start) and begin regulating the framerate with that variable as my point of reference? Trying to keep it extremely simple here, it seems that I wouldn't even need a timer class at all. I see the benefits of these member functions in a more advanced game but my main question is whether I will need them in the situation I've outlined.

##### Share on other sites
You're correct that you could do something simple like tetris without the timer class at all, just using the basic SDL functions, but the class offers reusability for future projects. Usually when using someone else's code (like the SDL API, for example) you'll never use every function of each class, they're written in case you might want that functionality. For example, if you use the container std::vector<T>, you might just utilize the push_back(), back(), and pop_back() functions, disregarding all the others.

sounds good :)

##### Share on other sites
Quote:
 Original post by BCullisYou don't need to use them, but they won't hurt anything to have around in the class for you to use later.

Yeah, it's not that hard to pause/stop a timer so if you can put it in even a simple first game it will be useful (who would play a game that you can't even pause [grin]).

btw, i don't think you would use the stop() function for when a player dies, at least, not for the framerate timer. But you will eventually need to time other things which need to be started and stopped (like maybe animations)

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628401
• Total Posts
2982467

• 9
• 10
• 9
• 19
• 24