This would work, call this method where ever you handle your MAIN game cycle:
Declare these variables:
private static int currentFPS = 0;
public static int Fps; //Actual frames per second
private static long start = 0;
public static int levelTime = 120; //120 seconds = 2 minutes
Add this method:
public static void updateFps() {
currentFPS++;
if (System.currentTimeMillis() - start >= 1000) {
levelTime -= 1; //We deduct 1 second, every second.
Fps = currentFPS;
currentFPS = 0;
start = System.currentTimeMillis();
}
}
Works fine, every second (1000 milliseconds, its removing 1 from that levelTime, which you could draw out like "Time remaining: "+levelTime.
Hope it helps m8.