The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Delta time using with movment.
tw3tye


Joined: 22 Jan 2012
Posts: 18
Hello. im kinda stuck here, so many forums and post and each one is not enought to show how to realy do it so im picking peace by peace.
Here is my main game loop, im trying to calculate float SpeedFactor so i can use it for movment.
This is my basic code. where do i put my stuff to get coresponding SpeedFactor i cant figure it out.
Code:

int main(int argc, char* argv[])
{
  float SpeedFactor;
  //Init
  //Load stuff
 while(On)
  {
   
   //Event
   //Actions
   //Render

  }
  //Quit
}

void Actions()
{
  HeroPositionX += HeroMovmentRate * SpeedFactor;
}
ste3e


Joined: 13 May 2011
Posts: 7
Location: NZ
From what I can see you need to grab the time difference between each loop and send that through to Actions. I use

Code:
Uint32 last = 0, delay = 0;

loop(){
    Uint32 now=SDL_GetTicks();
    if(now > last){
   delay=now - last;
   last=now;
    }
    Actions(delay);
}

void Actions(Uint32 delay)
{
  HeroPositionX += HeroMovmentRate * delay;
}
c1702


Joined: 24 Apr 2012
Posts: 3
Hello,

In addition to the previous answer, I found the following pages related to the subject :

http://gafferongames.com/game-physics/fix-your-timestep/
http://www.koonsolo.com/news/dewitters-gameloop/

Hope this can help. (I'm using fixed frame rate, so I never used this technique).

Clément.
tw3tye


Joined: 22 Jan 2012
Posts: 18
Thank you both figured it out somhow.