Public Group

# smooth ball flow giving trouble

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

## Recommended Posts

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.??

##### Share on other sites
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...

##### Share on other sites
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.

##### Share on other sites
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*/}

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013636
×