Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game programming and quantity of timers

I've made a simple 2D game engine using C# and DirectX and it's fully functional for the demo I made to test it. I have a Timer object that uses QueryPerformanceCounter and I don't know what's the better choice: use only one timer in the game loop to update everything in the game, or an independent timer in every object that needs one.

My worry is that when I try to implement threads, what will happen with timers? What happens with the sync?

like image 838
andresjb Avatar asked Oct 12 '12 22:10

andresjb


1 Answers

You had better to have an Update (user interaction and other calculatings like hittest) and Draw functions for each game object. Your timer should call the topmost Update method and this method will call the update methods of each object. Drawing can be done with another timer or just a while loop until game ends. My choice is having only one timer for update. For the differences of timers; Comparing the Timer Classes

like image 197
aliassce Avatar answered Nov 13 '22 13:11

aliassce