hi their I've been lurking on these forums for the last week or so and today I decided to make an account after being stuck with these issues (yay for leeching). I'm trying to make a game with java2d and I'm having issues recording the fps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| private long prevStatsTime; double fps = 0; int frameCount = 0; long totalElapsedTime = 0L;
public void run(){ ..... prevStatsTime = System.nanoTime(); while(running = true){ ..... beforeTime = System.nanoTime(); } ...... recordInfo(); }
public void recordInfo() { long realElapsedTime = System.nanoTime() - prevStatsTime;
frameCount++; totalElapsedTime += realElapsedTime; if(totalElapsedTime > 0) fps = (((double)frameCount/totalElapsedTime)*1000000000L); prevStatsTime = System.nanoTime(); }
public void drawInfo(Graphics g) { ... g.drawString("FPS: " + fps, 0, 30); } |
the issue I'm having is that the fps slowly decreases so obviously its not recording the fps >.< any help would be really great I would prefer a nudge in the right direction rather then you flat out explaining it to me if you wouldn't mind.
many thanks