From 551dddeb0a4c87b211f888ee070a91248e14844a Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 26 Nov 2025 20:27:39 +0100 Subject: [PATCH] Added game clock --- src/de/mp/jgame2d/core/Boot.java | 2 ++ src/de/mp/jgame2d/core/GamePanel.java | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/de/mp/jgame2d/core/Boot.java b/src/de/mp/jgame2d/core/Boot.java index b4e2cb6..b57a881 100644 --- a/src/de/mp/jgame2d/core/Boot.java +++ b/src/de/mp/jgame2d/core/Boot.java @@ -17,6 +17,8 @@ public class Boot { window.setLocationRelativeTo(null); window.setVisible(true); + + gamePanel.startGameThread(); } } diff --git a/src/de/mp/jgame2d/core/GamePanel.java b/src/de/mp/jgame2d/core/GamePanel.java index 94b9355..11c2e94 100644 --- a/src/de/mp/jgame2d/core/GamePanel.java +++ b/src/de/mp/jgame2d/core/GamePanel.java @@ -3,7 +3,7 @@ package de.mp.jgame2d.core; import javax.swing.*; import java.awt.*; -public class GamePanel extends JPanel { +public class GamePanel extends JPanel implements Runnable { // SCREEN SETTINGS final int originalTileSize = 16; //16x16 tile @@ -16,10 +16,33 @@ public class GamePanel extends JPanel { final int screenWidth = tileSize * maxScreenCol; // 768 pixels final int screenHeight = tileSize * maxScreenRow; // 576 pixels + Thread gameThread; + public GamePanel() { this.setPreferredSize(new Dimension(screenWidth, screenHeight)); this.setBackground(Color.black); this.setDoubleBuffered(true); } + public void startGameThread() { + gameThread = new Thread(this); + gameThread.start(); + } + + @Override + public void run() { + while(gameThread != null) { + update(); + repaint(); + } + } + + public void update() { + + } + + public void paintComponent(Graphics graphics) { + super.paintComponent(graphics); + } + }