Hi, I have almost finished the whole chat stuff on my game. I have 2 problems:
1.- WHen I press BackSpace once it seems to register twice or something becausse my event is fired two times. this is the code:
public void appendChatChar () {
//System.out.println ("Haciendo el appendChatChar: "+mensajeChat);
boolean estado=false;
do {
estadoTeclas=mapaTeclas.poll();
if (estadoTeclas!=KeyState.NONE) {
estado=estadoTeclas.getState ();
if (estadoTeclas.getKeyCode()==KeyEvent.VK_ENTER) {
//System.out.println ("enviando el mensaje");
mensajeSalida=mensajeChat;
chateando=!chateando;
render.setEnChat(false);
} else if (estadoTeclas.getKeyCode()==KeyEvent.VK_ESCAPE) {
//System.out.println ("dejando de chatear");
mensajeChat="";
chateando=!chateando;
render.setEnChat(false);
} else if (estadoTeclas.getKeyCode()==KeyEvent.VK_BACK_SPACE || estadoTeclas.getKeyCode()==KeyEvent.VK_DELETE) {
System.out.println ("BORRANDO UN CARACTER DEL CHAT");
if (mensajeChat.length()>=1)mensajeChat=mensajeChat.substring(0, mensajeChat.length()-1);
render.setMensajeChat(mensajeChat);
} else {
char C=estadoTeclas.getChar();
int h=C;
if (h!=0)mensajeChat=mensajeChat+C;
render.setMensajeChat(mensajeChat);
}
}
} while (estadoTeclas!=KeyState.NONE);
}
The estadoTeclas.getKeyCode()==KeyEvent.VK_BACK_SPACE is always being fired two times, always. Anyway to fix it?
2.- When I get get the events for my game everything goes well, but when doing the chat stuff, for each key typed and appended to a String I am receiving this: For example I write HELLO and get H(blank)E(blank)L(blank)L(blank)O(blank)
char C=estadoTeclas.getChar();
int h=C;//used this to control it
if (h!=0)mensajeChat=mensajeChat+C;
render.setMensajeChat(mensajeChat);
I guess Its a bug on the getChar method.