Thread.sleep in Gameloop für CPU Entlastung
Außerdem verringerte Debug Ausgabe bei Spielerbewegung
This commit is contained in:
1 parent
cf6cb9ad67
commit
0b9555b403
2 files changed
+12
-2
No files matched your search
@@ -177,6 +177,13 @@ public class GameLoopD extends JFrame implements Runnable {
|
|||||||
render();
|
render();
|
||||||
frames++;
|
frames++;
|
||||||
|
|
||||||
|
try {
|
||||||
|
thread.sleep(5); // entlastet die cpu massiv.
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if (System.currentTimeMillis() - timer > 1000) {
|
if (System.currentTimeMillis() - timer > 1000) {
|
||||||
timer += 1000;
|
timer += 1000;
|
||||||
System.out.println(updates +" Ticks, fps " + frames);
|
System.out.println(updates +" Ticks, fps " + frames);
|
||||||
|
|||||||
@@ -116,8 +116,6 @@ public class Player extends JComponent {
|
|||||||
|
|
||||||
this.setAutoBounds(newx, newy);
|
this.setAutoBounds(newx, newy);
|
||||||
|
|
||||||
//debug
|
|
||||||
System.out.println("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y);
|
|
||||||
|
|
||||||
currentCountX--;
|
currentCountX--;
|
||||||
|
|
||||||
@@ -128,6 +126,11 @@ public class Player extends JComponent {
|
|||||||
}
|
}
|
||||||
if (currentCountX <= 0) {
|
if (currentCountX <= 0) {
|
||||||
currentCountX = 25;
|
currentCountX = 25;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
System.out.println("on grid - x: "+getGridLocation().x + " y: "+getGridLocation().y);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user