LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   [SDL] help setting framerate?? (http://www.linuxquestions.org/questions/programming-9/%5Bsdl%5D-help-setting-framerate-119708/)

stateq2 11-25-2003 01:52 AM

[SDL] help setting framerate??
 
hi,

i'm a novice programmer, and i've been working on a break out clone (VERY early stages), and i can't figure out how to get a lower framerate.....if that's the problem. the game runs at 138 fps currently, and the ball moves much too fast. if anyone has experience w/ sdl, i'd appreciate it if you would have a look at the code, and give me some suggestions. i don't have a website, so i uploaded the file in another forum. thanks a million :)
http://www.dslreports.com/forum/rema...xdsl~mode=flat

CatSC 11-25-2003 04:26 AM

Get Ticks!
 
You need your game to be NOT based on fps, because it will run at different speed
on defferent computers.
you need to have a cycle which runs for as long as program runs
you also need to know how much time each cycle lasts
so let's say you have a variable "float x_cor" which is x position of the object...
then you have "float speed" which is how many PIXELS your object mover PER SECOND
you use "SDL_GetTicks()" function to find out for how much time passed from the start of the
program. Adding it all together you will get something like this

double Stime=0;

while(program_is_running==true)
{
double frame_time=(SDL_GetTicks()-Stime)/1000.0;

//Main part starts here
x_cor+=speed*frame_time;
//Main part ends here

Stime=SDL_GetTicks();
}


if you have any questions, ask!

stateq2 11-25-2003 10:45 AM

thanks alot :) because i had no idea where to start....i read something about GetTicks(), and included it in the game, but didn't quite know how to use it. i'm gonna try to implement what you posted. i'll reply about how i'm doing.....thanks again :)


All times are GMT -5. The time now is 05:53 PM.