Rendering and running a gameloop in an Applet

Still fighting the move from fullscreen graphics to an Applet with pseudo-doublebuffering :slight_smile:

Is this at all a good implementation of a gameloop in an applet?
http://pastebin.java-gaming.org/54a6b9d84

It seems legit and it runs fine, except that instead of getting the 60fps I’m aiming for, I’m getting 63-64.

I’ve been scouring the net and this forum for posts on gameloops and rendering-methods, and found
many good examples, but very few are written for Applets, and most are incredibly elaborate and hard
to decipher. I’ve tried to compile those many ideas into something that would work for me.

Also, even though ra4kings impeckable sleep-method is rad, I just feel it is odd that one
has to do so many calculations, just to make your loop sleep for a specific amount of time.
Why is this not good enough?

If your problem is that 63-64, then you shouldn’t worry.

ra4king’s sleep method is pretty good. I adopt his these later months. It’s not godly perfect but slight better.

Thanks for your reply :slight_smile:

Well, one thing I’m unsure of, is why those 3-4 extra frames are there. Mathematically, I don’t see where they’re coming from.

What I’m most interested in, is to know if this is a viable solution to the, well, single-buffering technique to reduce flicker.
This just seems much simpler than the ones I’ve found around the net.

The answer is simple, because getting time through System static class from OS especially windows is not accurate.

Yeah, I know. But it’s stable at 63-64. I guess I’ll live with that. Is that also the reason why the movement isn’t
completely smooth? I’ve added some balls, and they move about fine. It just seems like they randomly skip a tiny
bit every ½ a second or so.

http://pastebin.java-gaming.org/54a6b0d94

being stable at 63-64 is right. Thats what you programmed. You said him, he sould sleep “int sleepTime = 1000/FRAMERATE” and that means: sleepTime = 16. And with that sleepTime you should perfectly get 64 Frames/sec.

What I want is 60fps, which should be 1000000000ns/60 = 16666667 = 16,666667ms per frame. Setting it to 16ms flat, would produce 62,5fps, give or take.

Well, maybe what I need is to do as some threads on the forum suggest, and use Thread.yield() and a deltaLoop-timing system instead of sleep(),
as ReBiirth and others suggested in this older thread http://www.java-gaming.org/index.php?topic=22762.0
Oh I hope the Orcale guys fix this problem.

EDIT: I think I’ve found the solution. It has been posted in another thread, due to several changes in the code, and new questions.
Here is the new post!