Sign in to follow this  
Noobie

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


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this