|
-
November 11th, 2008, 04:12 PM
#1
Timing Game Speed.
How Would I go about timing how fast my game runs no matter the frame rate speed?
Limiting Frame speed does work, but I don't think frame speed is reliable on such an important aspect of game programming.
Thanks.
-
November 12th, 2008, 01:28 AM
#2
Re: Timing Game Speed.
Code:
DWORD dwTick;
DWORD dwLast;
float framespersec;
float secsperframe;
// Before the game loop begins...
dwLast = GetTickCount();
// For each iteration of the game loop...
dwTick = GetTickCount();
framespersec = 1000.0F / (float)(dwTick - dwLast)
secsperframe = (float)(dwTick - dwLast) / 1000.0F;
dwLast = dwTick;
It is important to use time base movement so things move the same speed on all computers.
Code:
const float unitspersec = 0.001F;
float distancetomove = secsperframe * unitspersec;
I hope i wrote all that right...lol
-
November 15th, 2008, 02:47 AM
#3
Re: Timing Game Speed.
What does / by float do?
And also, Do I put this in the main while loop before the render function, or do I put it in the frame rending function?
Thanks.
-
November 19th, 2008, 05:06 AM
#4
Re: Timing Game Speed.
Basically what he is saying that you make your code do animations or change not by the no. of frames but the no. of seconds that have passed. If you can implement that in your code on your own then you needn't use any code that he has written, however that'[s how many people would do it.
I'd suggest getting a book on making Game Engines, it doesn't matter whether it teaches you to make 2D games or 3D, the basic structure is what matters, the rest of the resources are easilly available on the internet. It might be possible for you to find some Game Engine tutorial online, and if that works for you then why not.
-
November 27th, 2008, 02:32 AM
#5
Re: Timing Game Speed.
Any game books you suggest?
Also I probably need to know a little more math like trig.
I'm only 16 so Id say I'm pushing a little, going into trig. 
Oh and btw, I think I know what 1000.0f / float is. Is it dividing by floats highest point?
-
December 2nd, 2008, 12:35 PM
#6
Re: Timing Game Speed.
Code:
framespersec = 1000.0F / (float)(dwTick - dwLast);
Means that i want the result of (dwTick - dwLast) to be casted into
floating point value before dividing 1000.0F by it, which is to prevent
the final result from being rounded into an integer value.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|