Hi there! I have coded a small demo, but it is using 100% of the CPU. How can I avoid this? Below is the run() method
I am running on win2000 and FPS=60. Is Thread.yield() not working or I missed something?
final int FRAME_LENGTH = 1000 / FPS;
long startTime = System.currentTimeMillis();
int frameCount = 0;
System.out.println(FRAME_LENGTH);
while (!this.quit) {
this.paint(this.getGraphics());
frameCount++;
while ((System.currentTimeMillis() - startTime) / FRAME_LENGTH < frameCount) {
System.out.println("fc=" + frameCount + " elapsed="
+ ((System.currentTimeMillis() - startTime) * 1000)
+ " fps=" + (float) frameCount
/ (System.currentTimeMillis() - startTime) * 1000);
frameCount = 0;
Thread.yield();
}
}