I am trying to add a small function to allow me to pause the game I am making.
I measure the time elapsed using the following algorithm:
1. USE ""clock_t begin=clock();"" FOR SYSTEM TIME OF GAME BEGINNING.
2. USE ""cout<<(clock()-begin)/CLOCKS_PER_SEC;"" TO DISPLAY TIME ELAPSED IN SECONDS.
Now, if I want to pause, I would want to subtract the 'paused' time from the total time elapsed.Say,
clock_t pause, resume;
Then I would do
This, though is what I want, works only once(I can pause only once).
I can use arrays of resume and pause, but it would still limit the number of times I can pause.
What I am looking for is a way to pause any number of times.
clock_t totalPause = 0;
totalPause += (resume - pause);
cout << (clock() - begin - totalPause)/CLOCKS_PER_SEC;
Last edited on
Ah! So wonderful and elementary. Thanks a lot for waking up a brain dead guy.