Jump to content
  • Advertisement
Sign in to follow this  
Noobie

SDL_GetTicks()

This topic is 4941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!