I’m having a bit of a problem with the smoothness of my graphics… or the lack of it!
I’m using a dead simple Applet and Thread, and the graphics are drawn using active rendering. My main loop is pretty traditional:
run()
{
gameLogic();
render(backBuffer);
swapBuffers();
try{gthread.sleep(20);}
catch (InterruptedException e){}
}
The game logic is non existent at the moment, so it basically just throws things at the screen.
The problem is that while it maintains a fairly constant speed, it’ll jerk/judder/stick every second or so. It’s perfectly smooth in-between these judders, which makes it seem like (to me) that something is interrupting my program periodically.
My other thought was that some frames may be taking vastly different times to draw than others, causing intermittent speedups/slowdowns. So, I tried using a Timer object to invoke the drawing of frames at a set rate, and it made absolutely no difference.
I also wrote a small method to calculate the amount of time taken to draw a frame, and subtracted that time away from a standard delay. I then made the thread sleep for this amount of time. This should make each cycle of the loop take roughly the same time… right? But it still behaves exactly the same…
I’ve tried the program on all sorts of hardware and Windoze versions.
Any suggestions?