This would work, call this method where ever you handle your MAIN game cycle:
Declare these variables:
1 2 3 4
| private static int currentFPS = 0; public static int Fps; private static long start = 0; public static int levelTime = 120; |
Add this method:
1 2 3 4 5 6 7 8 9
| public static void updateFps() { currentFPS++; if (System.currentTimeMillis() - start >= 1000) { levelTime -= 1; 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.