Replace the previous key handlers with the following code:
Item { id: player //... QtObject { id: flags readonly property int speed: 100 property int horizontal: 0 } Keys.onRightPressed: { recalculateDurations(); flags.horizontal = 1; } Keys.onLeftPressed: { if(flags.horizontal != 0) { return; } recalculateDurations(); flags.horizontal = -1; } Keys.onUpPressed: jump() Keys.onReleased: { if(event.isAutoRepeat) return; if(event.key === Qt.Key_Right) { flags.horizontal = 0; } if(event.key === Qt.Key_Left && flags.horizontal < 0) { flags.horizontal = 0; } } function recalculateDurations() { xAnimRight.duration = (xAnimRight.to - x) * 1000 / flags.speed; xAnimLeft.duration = (x - xAnimLeft.to) ...