I am developing a simple game in c++, a chase-the-dot style one, where you must click a drawn circle on the display and then it jumps to another random location with every click, but I want to make the game end after 60 seconds or so, write the score to a text file and then upon launching the program read from the text file and store the information into an array and somehow rearrange it to create a high score table. I think I can figure out the high score and mouse clicking in a certain area myself, but I am completely stuck with creating a possible timer. Any help appreciated, cheers!
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
Usually GUI program has so called "message pump" loop. Check of that timer should be a part of your loop:
Without reference to a particular framework or even the OS this is unanswerable.
In SDL there is
SDL_GetTicks()
which suits the purpose.On linux, there is the general purpose
clock_gettime
orgettimeofday
that should work pretty much everywhere (but beware of the details).Win32 API has several function calls related to this, including Timer callback mechanisms, such as
GetTickCount
,Timers
etc. (article)Using timers is usually closely related to the meme of 'idle' processing. So you'd want to search for that topic as well (and this is where the message pump comes in, because the message pump decides when (e.g.)
WM_IDLE
messages get sent; Gtk has a similar concept of Idle hooks and I reckon pretty much every UI framework does)Try this one out:
In C++11 there is easy access to timers. For example:
Your platform may or may not support
<chrono>
yet. There is a boost implementation of<chrono>
.