Added game clock
This commit is contained in:
@@ -17,6 +17,8 @@ public class Boot {
|
|||||||
|
|
||||||
window.setLocationRelativeTo(null);
|
window.setLocationRelativeTo(null);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
|
|
||||||
|
gamePanel.startGameThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user