Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Thread Variable
- private Thread gameThread;
- public synchronized void start() {
- if (running) {
- return;
- }
- running = true;
- gameThread = new Thread(this);
- gameThread.start();
- }
- public synchronized void stop() {
- if (!running) {
- return;
- }
- running = false;
- try {
- gameThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- // Der eigentliche Game Loop
- // Die Klasse implementiert Runnable
- public void run() {
- this.requestFocus();
- init();
- long lastTime = System.nanoTime();
- double amountOfTicks = 60.0;
- double ns = 1000000000 / amountOfTicks;
- double delta = 0;
- long timer = System.currentTimeMillis();
- while (running) {
- long now = System.nanoTime();
- delta += (now - lastTime) / ns;
- lastTime = now;
- while (delta >= 1) {
- tick();
- delta--;
- }
- render();
- if (System.currentTimeMillis() - timer > 1000) {
- timer += 1000;
- }
- }
- }
- // Alles Render Zeugs
- private void render() {
- }
- // Alle Updates
- private void tick() {
- }
- // Main Methode
- public static void main(String[] args) {
- new Game().start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement