i calculate my FPS like this
public void run() {
int FPS = 43;
long startTime, deltaTime;
while (Thread.currentThread() == animate) {
// calculating current FPS
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???