Hi everyone,
I have a problem thats really starting to do my head in! :’(
I have a online game that is run via an applet in a browser. It works OK, except that I can’t get consistent timing for the FPS. It has balls which move about, but sometimes they speed up/slow down non- linear manner. When I run the same game throught AppletViewer is nice and smooth. Its only when I run in an applet I have the issues. However I’m stuck using and applet as it needs to be easy and quick to use for the online users.
The code for the thread is :
long framerate = 1000 / 30; // frames per sec
long oldtime;
while (true) {
oldtime = System.currentTimeMillis();
// update object movement
// draw stuff
long currenttime = System.currentTimeMillis();
if (currenttime - oldtime < framerate) {
try {
Thread.sleep((oldtime + framerate) - currenttime);
} catch (InterruptedException e) {
}
}
Edited so say: I’m using a doubled BufferedImage to do the drawing. I’m not sure if its an issue with the consistency of the FPS or whether its the timing between calculating the movement of the objects. I’m not calling pain directly rather update() FYI.t