smooth ball flow giving trouble

Started by
2 comments, last by Daos 19 years, 8 months ago
I have made the game bricks where there is paddle to guide a falling ball to hit bricks wall above. The problem is that if i move the ball by some distance (say 2 pixel/millisecond, coz 1 looks too slow), it looks like as if the ball is flowing in steps. Now if i make the ball independent of timer and it falls 2 pixels every time , it looks pretty smooth, but it works at different speeds on different computers(trust me, one person complained that the game was virtually un playable on his machine, coz i think his machine is very very fast, whereas it was running just fine on my machine). how to solve this problem.??
Advertisement
You should have a fps timer - well you can use this to move the ball a certain distance per frame, and use how fast it goes on your computer to determine this:

if your computer runs the program at 88 fps and you have the ball moving 2 units per frame (and that's the speed you want) then have the ball moving at

2/88 * currentFPS

to have it move the same speed on all computers.

Or you can just put in a slider bar to adjust the speed manually...
I had the exact same problem with my first game - a pong clone, where you use a paddle to hit balls. You need to first find out what fps the game should run at, and then lock it.

I used GetTickCount:

while(TRUE){    startcount = GetTickCount();    // code here    while(GetTickCount() - startcount < 33)         Game_Main_Proc();  // main game processing}

This wuold lock at 30 fps. You basically divide 100 by the fps you need and replace 33 with that number, rounded up to an integer. E.g. 100 fps would need 10.

Good luck, hope that helped.
Check out my first game here.
It seems you need a more precise timer(or at least a multimidia timer which you certainly can do)
__int64 frequency;float resolution;//more than a milisec __int64 start,elapsed;unsigned long multimedia_timer_start;unsigned long multimedia_timer_elapsed;bool performance=false;/*see if you have a performance counter*/if(QueryPerformanceFrequency((LARGE_INTEGER*)&frequency)==true){//set resolutionresolution=(float)(1.0f/(double)frequency));if(!QueryPerformanceCounter((LARGE_INTEGER*)&start) /*handle the error*/performance=true;}else{resolution=1.0f/1000.0f;//one milisecond of precisionmultimedia_timer_start=timeGetTime();}/*check if it's time to draw your scene*/if(performance){QueryPerformanceCounter((LARGE_INTEGER*)&elapsed);if( ((elapsed-start)*resolution)*1000)>"your_time_gap in miliseconds")  {  start=elapsed;  DrawScene(); }else ;/*eat CPU cycles*/}else{multimedia_timer_start=timeGetTime();if( ((multimedia_time_elapsed-multimedia_time_start)*resolution)*1000)>"your_time_gap in miliseconds")  {  start=elapsed;  DrawScene();  }else ;/*eat CPU cycles*/}



To use timeGetTime ..Winmm.lib ;Mmsystem.h




This topic is closed to new replies.

Advertisement