PDA

View Full Version : My programm is to fast...help :)



PrinceofZ
11-04-2000, 06:29 AM
I write a little tetris clone...(i wanted to make something new http://www.opengl.org/discussion_boards/ubb/smile.gif )...i use the openGL api and the MS vc++6 compiler.
The problem: My programm is way to fast, when i hit the downkey the block i falling down instantly... so, how do i get my programm to make what i want http://www.opengl.org/discussion_boards/ubb/smile.gif

thx

Michael Steinberg
11-04-2000, 07:11 AM
Well, you have to make the image content time-dependant, not frame-number-dependant. If you are developing in Win32 try looking into QueryPerformanceCounter or the like. Then, say, any block would move a certain way in a second. This will make the blocks always move at the same speed, even if others will have another frame rate.

pleopard
11-20-2000, 03:40 PM
Or simply insert this between frames ...

{
unsigned long timeDelay = 1000; // msecs
Sleep(timeDelay);
}

snipe
11-22-2000, 01:44 PM
Methinks the call to sleep is the best solution

dans
11-22-2000, 06:54 PM
//init timer
long timer = GetTickCount();

your loop:

if (GetTickCount() - timer >= 1000) // 1 sec delay
{
// do your funky code
timer = GetTickCount(); //reset timer for next run
}

simple but works, this can be inacurate at times there is a higher resolution timer you may want to look into.

Dont use Sleep(); as that will halt the entire process at that point.