From 0b9555b403ff5d9642f572f43229eaaf0090e24a Mon Sep 17 00:00:00 2001 From: toksikk Date: Thu, 6 Nov 2014 21:07:53 +0100 Subject: [PATCH] =?UTF-8?q?Thread.sleep=20in=20Gameloop=20f=C3=BCr=20CPU?= =?UTF-8?q?=20Entlastung=20Au=C3=9Ferdem=20verringerte=20Debug=20Ausgabe?= =?UTF-8?q?=20bei=20Spielerbewegung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HeatUp/src/de/heatup/testing/GameLoopD.java | 7 +++++++ HeatUp/src/de/heatup/testing/Player.java | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/HeatUp/src/de/heatup/testing/GameLoopD.java b/HeatUp/src/de/heatup/testing/GameLoopD.java index c2fef74..adef59c 100644 --- a/HeatUp/src/de/heatup/testing/GameLoopD.java +++ b/HeatUp/src/de/heatup/testing/GameLoopD.java @@ -177,6 +177,13 @@ public class GameLoopD extends JFrame implements Runnable { render(); frames++; + try { + thread.sleep(5); // entlastet die cpu massiv. + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (System.currentTimeMillis() - timer > 1000) { timer += 1000; System.out.println(updates +" Ticks, fps " + frames); diff --git a/HeatUp/src/de/heatup/testing/Player.java b/HeatUp/src/de/heatup/testing/Player.java index 95f5c00..96ed5ca 100644 --- a/HeatUp/src/de/heatup/testing/Player.java +++ b/HeatUp/src/de/heatup/testing/Player.java @@ -116,9 +116,7 @@ public class Player extends JComponent { this.setAutoBounds(newx, newy); - //debug - System.out.println("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y); - + currentCountX--; if ( currentCountX <= 0 ) { @@ -128,6 +126,11 @@ public class Player extends JComponent { } if (currentCountX <= 0) { currentCountX = 25; + + //debug + System.out.println("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y); + + } }