How to use the timedelta variable for device independent timing?

Home / Support / Frequently Asked Questions / How to use the timedelta variable for device independent timing?

The onnextframe game loop offers the timedelta parameter. When using the timedelta parameter it's a good idea to measure animations in "units" rather than pixels (because the timedelta variable is usually bigger than the amount of pixels to move). It's not a good idea to divide the timedelta parameter, because the amount of movement may be 0 if the timedelta parameter contains a low value (this will be the case if the game runs at a high fps).

For example, when moving sprites, update the x-position of the sprite using timedelta (sprite[0]->x += timedelta). When drawing, convert the "unit position" back to the position in pixels and draw it onscreen.

A good example of using timedelta is shown in the Blastar sample and tutorial.

Back to FAQ

Latest forum posts