Okay, your explanation did help give me better results. I can now jump and move at the same time and continue moving. I utilized a Timer and set a flag on the player. While this does make things a lot smoother. My next issue is this (and I still find it's related to the key events). If I'm holding down the right key and my character goes to the right, AND THEN I hold the left key down, my character starts moving left (that's fine). If I let go of the left key, my flag resets to zero instead of catching that the right key is still held down and it should go back to 1 (-1 = left, 1 = right). It's only a real problem if I'm trying to slow my character down by "tapping" the opposite direction. I don't know how to accomplish this with the release events since I don't want a "tap" to keep me from continuing in the same direction. I appreciate the help, thank you very much.
Keys.onLeftPressed: {
if(event.isAutoRepeat) return;
player.moveHoriz = -1;
player.startTimer();
}
Keys.onRightPressed: {
if(event.isAutoRepeat) return;
player.moveHoriz = 1;
player.startTimer();
}
Keys.onUpPressed: {
player.jump();
}
Keys.onReleased: {
if (event.isAutoRepeat)
return ;
if (event.key == Qt.Key_Left &&
event.key == Qt.Key_Right) {
player.moveHoriz = -player.moveHoriz;
return ;
} else if (event.key == Qt.Key_Left || event.key == Qt.Key_Right){
player.moveHoriz = 0;
}
}
}
Keys.onLeftPressed: {
if(event.isAutoRepeat) return;
player.moveHoriz = -1;
player.startTimer();
}
Keys.onRightPressed: {
if(event.isAutoRepeat) return;
player.moveHoriz = 1;
player.startTimer();
}
Keys.onUpPressed: {
player.jump();
}
Keys.onReleased: {
if (event.isAutoRepeat)
return ;
if (event.key == Qt.Key_Left &&
event.key == Qt.Key_Right) {
player.moveHoriz = -player.moveHoriz;
return ;
} else if (event.key == Qt.Key_Left || event.key == Qt.Key_Right){
player.moveHoriz = 0;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks