FPS Counter

Hi. How would i make a timer thing that counts how many frames per second my applet is spitting out?
[107 byte] By [Futurisdom_Developera] at [2007-10-3 4:39:42]
# 1

I assume you have a game loop something like:

while( running ) {

doStuff();

paint();

waitForNextTick(); //?

}

You just need add a counter, and some time checking.

int fps = 0;

long lastFPS = System.currentTimeInMills() + ONE_SECOND_IN_MILLS;

while( running ) {

doStuff();

paint();

waitForNextTick();

fps++;

if( lastFPS < System.currentTimeInMills() ) {

System.out.println( fps );

fps=0;

lastFPS = System.currentTimeInMills() + ONE_SECOND_IN_MILLS;

}

}

mlka at 2007-7-14 22:43:38 > top of Java-index,Java Essentials,Java Programming...