The GameController module provides a simple NES-style controller abstraction with directional axis controls and two action buttons. It supports multiple input sources that can be switched at runtime.
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() }
See also GameController.
A unified game input system supporting keyboard, gamepad, and touchscreen |