Using Timers

Started by ug02070, March 15, 2005, 22:50:59

Previous topic - Next topic

ug02070

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 :)

Matzon

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.

elias4444

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.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

BatKid

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. ;)
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment