Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Was thinking this morning, I 99.9% of the time, only see a main game loop, looking like this, just as much so where the delta is passed into update():

while running

Now the question I was thinking to myself was what if between getDeltaTime() and f(deltaTime), the code in the middle took 1 second (large value to be easy). That means f(deltaTime) would have moved whatever object less distance than it was supposed to. This would of course be solved by grabbing the delta time directly before it is used.

Should this be a factor to be concerned with in any case?

share|improve this question
up vote 1 down vote accepted

deltatime is the time between two consecutive calls to getDeltaTime(). If a particular frame takes very long, that will show in the next iteration, and the model will be updated accordingly.

That being said, you're right: you should call f(..) straight away. Other code after it. Delays introduced by that extra code, as well as the time it takes to update the model itself, will show in the delta of the next frame.

share|improve this answer
That makes sense, not something I have considered before, but I will keep immediate calling in mind. – Rick Taemen May 30 '13 at 9:56

Yes, it is a factor. Some engines take this into account in some cases. For example AndEngine and its LimitedFPSEngine:

public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException {
    final long preferredFrameLengthNanoseconds = this.mPreferredFrameLengthNanoseconds;
    final long deltaFrameLengthNanoseconds = preferredFrameLengthNanoseconds - pNanosecondsElapsed;

    if (deltaFrameLengthNanoseconds <= 0) {
    } else {
        final int sleepTimeMilliseconds = (int) (deltaFrameLengthNanoseconds / TimeConstants.NANOSECONDS_PER_MILLISECOND);

        super.onUpdate(pNanosecondsElapsed + deltaFrameLengthNanoseconds);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.