I have experienced weird behaviour while coding a simple game. Basically, I create a thread with an infinite loop that fires an event in my game every couple of seconds. With the Sysout(runAnimation) in place everything works fine. However as soon as I remove it the even stops occurring.
It appears that the system.out calll is affecting the behavior of the program, does anyone have an idea why this could be happening
Here is the loop:
private void run(){
long lastTime = -1;
while(true){
int timePerStep = (int) Math.ceil(ANIM_TIME/frequency);
System.out.println(runAnimation);
if(runAnimation && System.currentTimeMillis() - lastTime > timePerStep){
lastTime = System.currentTimeMillis();
controller.step();
try {
Thread.sleep(timePerStep);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
It's started during the construction of my class as follows:
animThread = new Thread(new Runnable() {
@Override
public void run() {
GUIView.this.run();
}
});
animThread.start();