Hey everyone, I'm having an issue with my keyPress events. My problem happens when I hold down one key, and press another (not held) at the same time. Basically, think of playing Super Mario where you're running left, right, and jumping. Well, my character moves left, right and jumps... but if I'm moving right or left and press jump, my character stops moving left or right.
Now, I've looked into my code and can only conclude it's a problem in the key events. This is my code:
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
console.log("Left")
player.moveHoriz = -1;
player.moveBackward();
}
else if (event.key == Qt.Key_Right) {
console.log("Right")
player.moveHoriz = 1;
player.moveForward();
}else if (event.key == Qt.Key_Up) {
console.log("Jump")
player.jump();
}
} Keys.onReleased: {
if (event.isAutoRepeat)
return ;
if (event.key == Qt.Key_Left ||
event.key == Qt.Key_Right) {
player.moveHoriz = 0;
return ;
}
//if (event.key == Qt.Key_Up){
// return ;
//}
}
Keys.onPressed: {
if (event.key == Qt.Key_Left) {
console.log("Left")
player.moveHoriz = -1;
player.moveBackward();
}
else if (event.key == Qt.Key_Right) {
console.log("Right")
player.moveHoriz = 1;
player.moveForward();
}else if (event.key == Qt.Key_Up) {
console.log("Jump")
player.jump();
}
} Keys.onReleased: {
if (event.isAutoRepeat)
return ;
if (event.key == Qt.Key_Left ||
event.key == Qt.Key_Right) {
player.moveHoriz = 0;
return ;
}
//if (event.key == Qt.Key_Up){
// return ;
//}
}
To copy to clipboard, switch view to plain text mode
If I run my game in a console, this is what is happening behind the scenes.

As you can see, my held-key event is broken upon jumping. I have to take my finger off of my held key (such as the right arrow) and press it again to start moving right once again. I know that QML is not the best tool for building games in, but I'm sure it can't be this limited in key event control. If it makes a difference, I'm on Ubuntu 14.04 - Linux Kernel 3.13.0-43-generic.
Thanks for the help.
Bookmarks