time or timer in a 'REAL TIME'game
Alright,i''m trying to use a time contral in game
the game is ''real time'' ,i need enough time to contral other
units(they so various) but it won''t affect user''s contral and hero''s walk and so on.
Using ''CurrentTime-OldTime'',a timer?
Or, a high resolution timer?
Which is best?
And any other i can use?
If you want to create an RTS, the computer should not have more time to carry out moves than any other player. For each iteration of the game loop, any and all units that need to be moved or updated are, regardless of the player, and then the program loops around and moves them all again (as well as carry out other functions). What you''re really looking for is a timer to control how fast the loop iterates (controlling the frame rate). If it loops too fast, the units will move too fast! Try this:
The function I used (GetTickCount) is a WIN32 API so includeing windows.h is all you need. Note you can change the millisecond amount but 30fps should be good enough right? Peace.
******************************
"I do not fear computers, I fear the lack of them"
- Isaac Asimov
Drew Sikora
Napali Networks, Inc.
// MAIN GAME LOOPwhile(TRUE){ // Get the starting time DWORD start_time = GetTickCount(); ///////////////////////////////////////////////////////// // Do any checks for messages and game processing here // ///////////////////////////////////////////////////////// // wait for 33ms (30fps) while((GetTickCount() - start_time) < 33 );} // end game loop
The function I used (GetTickCount) is a WIN32 API so includeing windows.h is all you need. Note you can change the millisecond amount but 30fps should be good enough right? Peace.
******************************
"I do not fear computers, I fear the lack of them"
- Isaac Asimov
Drew Sikora
Napali Networks, Inc.
******************************"I do not fear computers, I fear the lack of them" - Isaac AsimovDrew SikoraNapali Networks, Inc.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement