From 529effeb12e63de0c8da429409c9693ad223c321 Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 26 Nov 2025 20:49:31 +0100 Subject: [PATCH] display actual fps in console --- src/de/mp/jgame2d/core/GamePanel.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/de/mp/jgame2d/core/GamePanel.java b/src/de/mp/jgame2d/core/GamePanel.java index bb2d722..293a3f6 100644 --- a/src/de/mp/jgame2d/core/GamePanel.java +++ b/src/de/mp/jgame2d/core/GamePanel.java @@ -46,16 +46,25 @@ public class GamePanel extends JPanel implements Runnable { double delta = 0; double lastTime = System.nanoTime(); long currentTime; + long timer = 0; + int drawCount = 0; while(gameThread != null) { currentTime = System.nanoTime(); delta += (currentTime - lastTime) / drawInterval; + timer += currentTime - lastTime; lastTime = currentTime; if(delta >= 1) { update(); repaint(); delta--; + drawCount++; + } + if(timer >= 1000000000) { + System.out.println("FPS: " + drawCount); + drawCount = 0; + timer = 0; } } }