Timing

From DmWiki

Time based executions are essential in game development. You need it for all sorts of things. Ex: animation that takes the same time to complete from one machine to another. Or say you want to interpolate a camera from point A to point B over a pre-defined time-period. You don't want the movement of the camera to finish in 2 seconds on a 2GHz computer and 10 seconds on a 200MHz computer! You want it to finish in the same time on both computers. Granted the transition will be smoother on the faster computer, but at least it wont be inaccurate.

A simple code example:

float lastFrameTime = myengine->getLastFrameDuration(); // How long the last frame took in seconds
float speed = 3; // 3 units per second
this.x += lastFrameTime * speed;

This article is a stub. You can help improve the article by expanding it.


DevMaster navigation