Sign in to follow this  

smooth ball flow giving trouble

This topic is 4862 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

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


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


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


Link to post
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 resolution
resolution=(float)(1.0f/(double)frequency));
if(!QueryPerformanceCounter((LARGE_INTEGER*)&start)
/*handle the error*/
performance=true;

}else
{
resolution=1.0f/1000.0f;//one milisecond of precision
multimedia_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




Share this post


Link to post
Share on other sites

This topic is 4862 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.

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