← Back to Docs
  • index.html
  • Clayground
  • Clayground GameController Module
  • Clayground 2025.2
  • Clayground GameController Module

    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.

    Usage

    Import the module:

    import Clayground.GameController

    Keyboard Input

    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"
    }

    Touchscreen Gamepad

    GameController {
        id: controller
        Component.onCompleted: selectTouchscreenGamepad()
    }

    Input Sources

    See also GameController.

    GameController

    A unified game input system supporting keyboard, gamepad, and touchscreen