Added game clock

This commit is contained in:
2025-11-26 20:27:39 +01:00
parent ac076e90b5
commit 551dddeb0a
2 changed files with 26 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ public class Boot {
window.setLocationRelativeTo(null); window.setLocationRelativeTo(null);
window.setVisible(true); window.setVisible(true);
gamePanel.startGameThread();
} }
} }

View File

@@ -3,7 +3,7 @@ package de.mp.jgame2d.core;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
public class GamePanel extends JPanel { public class GamePanel extends JPanel implements Runnable {
// SCREEN SETTINGS // SCREEN SETTINGS
final int originalTileSize = 16; //16x16 tile final int originalTileSize = 16; //16x16 tile
@@ -16,10 +16,33 @@ public class GamePanel extends JPanel {
final int screenWidth = tileSize * maxScreenCol; // 768 pixels final int screenWidth = tileSize * maxScreenCol; // 768 pixels
final int screenHeight = tileSize * maxScreenRow; // 576 pixels final int screenHeight = tileSize * maxScreenRow; // 576 pixels
Thread gameThread;
public GamePanel() { public GamePanel() {
this.setPreferredSize(new Dimension(screenWidth, screenHeight)); this.setPreferredSize(new Dimension(screenWidth, screenHeight));
this.setBackground(Color.black); this.setBackground(Color.black);
this.setDoubleBuffered(true); 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);
}
} }