The GameController module provides one controller abstraction in two layouts: nes, a stick and two action buttons, and full, two sticks, A/B/X/Y, shoulders, triggers and start/select. It supports multiple input sources that can be switched at runtime; each sets the inputs of the chosen layout.
Import the module:
import Clayground.GameController
GameController {
id: controller
Component.onCompleted: {
selectKeyboard(Qt.Key_W, Qt.Key_S, Qt.Key_A, Qt.Key_D,
Qt.Key_Space, Qt.Key_Return)
}
}
Rectangle {
x: x + controller.axisX * 5
y: y - controller.axisY * 5
color: controller.buttonAPressed ? "red" : "blue"
}
GameController { id: controller Component.onCompleted: selectTouchscreenGamepad() }
GameController { id: controller layout: "full" Component.onCompleted: selectKeyboard({ axisX: [Qt.Key_A, Qt.Key_D], axisY: [Qt.Key_S, Qt.Key_W], axisRightX: [Qt.Key_J, Qt.Key_L], axisRightY: [Qt.Key_K, Qt.Key_I], buttonA: Qt.Key_Space, buttonB: Qt.Key_Shift, buttonX: Qt.Key_F, buttonY: Qt.Key_R, buttonL1: Qt.Key_Q, buttonR1: Qt.Key_E, triggerL2: Qt.Key_1, triggerR2: Qt.Key_3, buttonSelect: Qt.Key_Tab, buttonStart: Qt.Key_Return }) }
GameController { id: controller layout: "full" function pickSource() { if (numConnectedGamepads > 0) selectGamepad(0) else selectTouchscreenGamepad() } Component.onCompleted: pickSource() onNumConnectedGamepadsChanged: pickSource() }
See also GameController.
A unified game input system supporting keyboard, gamepad, and touchscreen | |
Internal singleton listing the connected physical gamepads |