Calculating Delta time , what is wrong?
- by SteveL
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()
{
timesincestart=getTimeMil();
_director->Render();
_director->Update();
float dif=(getTimeMil()-timesincestart);//usally its about 5 milliseconds
lastcheck++;
sumdelta+=dif;
if(lastcheck>20)
{
sumdelta=sumdelta/20;
delta=sumdelta;
sumdelta=0;
lastcheck=0;
}
LOGI("delta:%f",delta);
}