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

For 2 days now i am trying to calculate the correct delta time for my game , I am starting to getting crazy since i tried all the solutions that i found on the 5 first google pages... What is wrong? I cant get the correct delta time ,whatever i tried is just not working , the delta goes from 1 to 4 and then back 1 and then to 3 even if i take the averange delta between many frames.Plus the game runs way much faster(i mean the movement) on slow devices than in fast. The game runs on android so the spikes between frames are expected.

My code is this:

    void Game::render()



        float dif=(getTimeMil()-timesincestart);//usally its about 5 milliseconds




void Game::render()

    delta=(newtime-oldtime)/16;//divide by 16 is just making the dt closer to 1


share|improve this question
"divide by 16"? Why would you do that? If you got milliseconds and need seconds (what your comment suggests, as you want the value to be "closer to 1") then do (newtime - oldtime) * 0.001 – bummzack Dec 5 '12 at 7:10
up vote 5 down vote accepted

i am a bit confused with your delta...

But how i do it is like this :

while( 1 ) 
    old = newTime;
    newTime = GetTime();

    DoMyGameAndUseLotsOfCyckels( newTime - old );
share|improve this answer
I tried before something similar and simple to this but it wasn't working . I tried exactly what you said and it is working . Simplicity is the best! – SteveL Dec 4 '12 at 14:01
indeed it is. i was confused with this along time aswell due to everything you read on the internet. So im glad it helpt – Tordin Dec 4 '12 at 14:16

Read Gaffer's article, Fix your Timestep. Understand how time accumulators work. Implement them. And apply actual time delta to physics and rendering, rather than some assumed constant dt. See if that serves you better.

Because in the end, if the time delta is varying wildly on your given platform, there is nothing you can do about that but to simulate around it as described above.

share|improve this answer

A mistake that I made this week doing this :

while (!quit){

startTime = SDL_GetTicks();  

Process Input();

Update Game(); 


endTime = SDL_GetTicks();

DeltaTime = endTime - startTime;

I do not know exactly Why, But this did not work at all. the solution @Tordin gave is the best one, and I have seen it in many many many references and books. ++

Hope this might help someone else because this link pops up in google very fast when you write Delta Time C++ Game Engine;

Edit: I think this dosent work correctly, because some things are happening between startTime and endTime;

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.