I’m currently using events. But is it possible to check whether a certain button is pressed every frame? For example Input.isKeyPressing(KeyCode.A). Since sometimes I encounter cases where the event does not fire when the key is released and my character continues to walk indefinitely (code when releasing the key moveRight = false)
The Input event listener are not working as expected ?
I expect the key release event to be fired always after the press event. But sometimes (in very rare cases, I don’t even know how to specifically repeat this) after the key is released, the goRight variable remains true (although after the release event it should be false)
onKeyDown (event: EventKeyboard) {
switch(event.keyCode){
case KeyCode.KEY_A:{
this.goLeft = true;
break;
}
case KeyCode.KEY_D:{
this.goRight = true;
break;
}
case KeyCode.KEY_W:{
break;
}
case KeyCode.KEY_S:{
break;
}
case KeyCode.SPACE:{
this.jumping = true;
break;
}
}
}
onKeyUp (event: EventKeyboard) {
switch(event.keyCode){
case KeyCode.KEY_A:{
this.goLeft = false;
break;
}
case KeyCode.KEY_D:{
this.goRight = false;
break;
}
case KeyCode.KEY_W:{
break;
}
case KeyCode.KEY_S:{
break;
}
case KeyCode.SPACE:{
this.jumping = false;
break;
}
}
}
onKeyUp (event: EventKeyboard) {
switch(event.keyCode){
case KeyCode.KEY_A:{
this.goLeft = false;
break;
}
case KeyCode.KEY_D:{
this.goRight = false;
break;
}
case KeyCode.KEY_W:{
break;
}
case KeyCode.KEY_S:{
break;
}
case KeyCode.SPACE:{
this.jumping = false;
break;
}
}
}
I understood how this happens. If you release the mouse key and the keyboard key at the same time, the keyboard release event will not fire. BUT. I made a build for the browser, everything works well there and there is no bug. This only happens in the editor
My code for mouse events:
mouseMove(event: EventMouse){
event.getUILocation(this.lastMousePos);
}
mouseDown(event: EventMouse){
this.firing = true;
}
mouseUp(event: EventMouse){
this.firing = false;
}