← Back to Docs
  • index.html
  • Clayground
  • Clayground.Canvas
  • ClayCanvas
  • Clayground 2025.2
  • ClayCanvas QML Type

    A 2D canvas with world coordinate mapping and camera controls. More...

    Import Statement: import Clayground.Canvas

    Detailed Description

    ClayCanvas provides a complete 2D rendering system with world unit coordinates, viewport management, camera following, and debug visualization. It transforms between screen pixels and world units automatically.

    The coordinate system uses Y-up orientation (like standard math coordinates).

    Example usage:

    import Clayground.Canvas as Canv
    
    Canv.ClayCanvas {
        id: canvas
        anchors.fill: parent
        worldXMin: -10; worldXMax: 10
        worldYMin: -10; worldYMax: 10
        pixelPerUnit: 50
        observedItem: player
    }

    Properties

    Automatic scaling factor based on device height (height / 1080).

    Zoom level multiplier. Default is 1.0.

    Number of screen pixels per world unit.

    Whether the canvas viewport can be panned interactively.

    Minimum X coordinate boundary in world units.

    Maximum X coordinate boundary in world units.

    Minimum Y coordinate boundary in world units.

    Maximum Y coordinate boundary in world units.

    Current viewport left edge position in world units.

    Current viewport top edge position in world units.

    Viewport width in world units.

    Viewport height in world units.

    X coordinate of viewport center in world units.

    Y coordinate of viewport center in world units.

    Whether to show the debug overlay with coordinate grid. Toggle with Space key.

    Enable keyboard navigation (IJKL for pan, E/D for zoom).

    The coordinate system container. Child items should be parented to this.

    Item that the camera follows automatically. Set to null to disable following.

    Methods

    Converts a world X coordinate to screen X coordinate.

    Converts a screen X coordinate to world X coordinate.

    Converts a world Y coordinate to screen Y coordinate.

    Converts a screen Y coordinate to world Y coordinate.

    Signals

    Emitted when a key is pressed while the canvas has focus.

    Emitted when a key is released while the canvas has focus.