You Like My Tutorials? Click The Banner To Keep 'Em Coming!

glGameDeveloper(): The Game Developer's Source for OpenGL Coding
Main Menu
Latest News
Archived News
Tutorials
Links
E-Mail Me

Other
Message Board
My Guestbook

Tutorials -- Updating Games Based on Time
 


Updating Your Game Based on Time Page 3 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

Using the GetTimePassed() Function

This function will return the time passed in milliseconds since the last update. It returns a decimal number, like 0.030 for 30 milliseconds. We need a decimal number so we can multiply other numbers with it.

To call the function, enter a line similar to this before you update objects in the game. In the Basic OGL tutorial, put it at the beginning of Idle().

float t = GetTimePassed();

Then you will have the time passed stored in the variable t. Now for example, say we want to move the player forward at a velocity of 0.1. Instead of adding 0.1 to the players position, we'd add 0.1 * t. This may not be fast enough, so you'll definitely have to tweak around with it. I usually multiply t by a number like 15 or 20 before using it. If you're having problems with it being too slow, definitely try this before e-mailing me about it.

And so this tutorial comes to a close. I hope it's helped you out a little. If you have any questions, feel free to ask me or post it on the Message Boards.

Updating Your Game Based on Time Page 3 of 3
< Previous Jump to Page: 1 | 2 | 3 Next >

This site best viewed with MS Internet Explorer 5.0 at 16-bit color and at least 800x600.

All Contents of this site are Copyright 1999, 2000 Joe Zimmerman. No part of this site (code, HTML, etc.) may be reproduced without my permission.

Click Here!