SDL_GetTicks()

Recommended Posts

Ok folks i gave up trying to figure out how to work this funcion... what do you need to write in the prog to make this command work ? im tying to learn SDL and using this to set up a very simple animation funtion that will flash a square with two colors in the same location every second but i can't make this thing work.... i did a couple of googles but the info on the funcion do not give good examples... Thanks in advance

Share on other sites
What are you trying? Something like this should work:

unsigned int current_time = SDL_GetTicks();

Share on other sites
forewarning: i dont use sdl

Based off of a quick check of the man pages, i see that SDL_GetTicks() returns the number of ms since the initialization on the SDL library.

So to create a horrid ugly animation loop to do what you want, in pseudocode:

uint l_time = SDL_GetTicks();uint c_time = SDL_GetTicks();while (1){   if ((c_time - l_time) > 1000)   {      callDisplayStuffHere();      l_time = c_time;   }   c_time = SDL_GetTicks();}

edit: ve been staring at c# code all day and Im a bit tired, so i may be completely wrong, you never know with me.

Share on other sites
int start_time = SDL_GetTicks()bool running = true;while(running){    if(SDL_GetTicks - start_time >= 1000)    {       switch(frame)       {          case 1: draw();                  frame = 2;                  start_time = SDL_GetTicks();                  break;          case 2: draw();                  frame = 1;                  start_time = SDL_GetTicks();                  break;       }     }       SDL_Flip(screen);}

Share on other sites
Thanks guys finally got it to work with your help :)

Create an account

Register a new account

• Forum Statistics

• Total Topics
628391
• Total Posts
2982419

• 10
• 9
• 19
• 24
• 11