Why is my while loop freezing up my program?
gameLoop() is holding up my other programs processes.
while (running) {
if (Key.up) {
player.moveCharacter(1, playerSpeed);
} else if (Key.down) {
player.moveCharacter(2, playerSpeed);
} else if (Key.left) {
player.moveCharacter(3, playerSpeed);
} else if (Key.right) {
player.moveCharacter(4, playerSpeed);
}
}
// listen for log in data
while (true) {
try {
int direction = socketIn.readByte(); // player direction
// sent from server
int px = socketIn.readByte(); // player px
int py = socketIn.readByte(); // player py
String username = socketIn.readUTF(); // player username
player = new Player(direction, px, py, username); // create
break;
} catch (IOException e) {
e.printStackTrace();
break;
}
}
game.gameLoop(player);
game.gameLoop(player); calls my game loop as you can see, however when it's run my game seizes to continue it's other processes. Can anybody tell me why this is happening? Do I need to put it on a thread?
while (true)without break condition.