LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: ug02070 on March 15, 2005, 22:50:59

Title: Using Timers
Post by: ug02070 on March 15, 2005, 22:50:59
Can someone please show me how i am able to use the timer functions within lwjgl to control the speeds at which my models move. currently i am subtracting sys.gettime from the last time i called it, each loop, which is used in the space invaders packaged with lwjgl.
What i need though is a way to ensure that my game runs at the same kind of speed on all pc's, and as models are being shot and being removed..that the shots dont go quicker and quicker until it gets from a nice steady speed to rapid fire!
thanks
Danny :)
Title: Using Timers
Post by: Matzon on March 16, 2005, 06:18:12
The easiest way is to synchronize to a FPS - so you can just use Display.sync
However, that means your game can run no faster than your sync rate (which is FINE for most games, even Doom3 locks @ 60 FPS).
Alternatively you need to use time based movement, which involves you calculating how much time went since last render, and then move all your stuff based on that time.
Title: Using Timers
Post by: elias4444 on March 16, 2005, 15:23:38
QuoteThe easiest way is to synchronize to a FPS - so you can just use Display.sync. However, that means your game can run no faster than your sync rate (which is FINE for most games, even Doom3 locks @ 60 FPS).
Alternatively you need to use time based movement, which involves you calculating how much time went since last render, and then move all your stuff based on that time.

I recommend the second solution, so in case your game isn't capable of running at the full FPS (SO much depends on hardware these days), the game will still move at the correct speed. It's not that hard, just subtract the last time punch from the current time punch, and then multiply your animation speeds by the difference.
Title: Using Timers
Post by: BatKid on March 24, 2005, 16:57:18
If you are going to use the time based method, make sure that your collision detection (if you are doing collision detection) is line based instead of point based.  Otherwise, on slower machines, you may have fast moving objects be able to move thru walls. ;)