i calculate my FPS like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public void run() { int FPS = 43; long startTime, deltaTime; while (Thread.currentThread() == animate) { newTime = System.currentTimeMillis(); if (newTime > oldTime+1000) { System.out.println("FPS: " + ticks); lastTicks = ticks; ticks = 0; oldTime = newTime; } ticks++;
startTime = System.currentTimeMillis(); repaint(); deltaTime = System.currentTimeMillis() - startTime; while (deltaTime < (1000/FPS)) { try { Thread.sleep((1000/FPS)-deltaTime); } catch (Exception e) { e.printStackTrace(); } deltaTime = System.currentTimeMillis() - startTime; } } } |
but i got only 34 fps in output
then i change FPS variable to 100, it increase to 43...
what's wrong with my code???