Mail Archives: djgpp/1999/01/31/02:05:25
Dylan Trotter wrote:
>
> I have been programming for a while, and have a good grip on how to program
> the system timer using an interrupt service routine to create a useful
> timing system, but I fail to grasp how to time things so that they are the
> same speed on all machines, so that the frames per second differ depending
> on the speed of the machine. Please note that I am referring to game
> programming.
Actually, you don't necessarily even need interrupts, just some sort of
fairly high-res timer. I would make the main loop something like this:
- Read the timer and determine how much time has elapsed since the last
loop
- Update the state of the game (positions, etc) based on this elapse.
So, if 0.02 seconds have elapsed, and you have an object moving 100
pixels/second, move it 2 pixels.
- Render the frame and draw it to the screen.
- Repeat, as fast as possible.
That way, you only get as many frames per second as you can, while the
game speed stays constant.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -