@like2d/like
    Preparing search index...

    Interface Canvas

    A manager for the HTML canvas element, similar to love.window.

    Controls game size / scaling -- both native and pixelart mode via Canvas.setMode, as well as fullscreen functions.

    The canvas keeps two canvases: render and display. Each frame, it copies render to display before the canvas is presented. This allows for pixel-accurate scaling in fixed mode.

    interface Canvas {
        getContext(): CanvasRenderingContext2D;
        getFullscreen(): boolean;
        getMode(): { flags: CanvasModeOptions; size: Vector2 };
        getRect(): Rectangle;
        getSize(): Vector2;
        hasFocus(): boolean;
        setFullscreen(fullscreen: boolean): void;
        setMode(size: CanvasSize, flags?: Partial<CanvasModeOptions>): void;
    }
    Index

    Methods

    • Escape hatch: use at your own risk!

      Get the 2d canvas context that graphics functions render to. This is separate from the display canvas; it is not visibly exposed but rather copied each frame.

      Returns CanvasRenderingContext2D

    • Set fullscreen.

      Parameters

      • fullscreen: boolean

      Returns void

    • Set the game's apparent resolution, fullscreen, etc.

      Parameters

      • size: CanvasSize

        Keeps the canvas pixel resolution the same as the physical pixel resolution of the device.

        The canvas will use prescaling to keep your pixel games looking sharp, but without the uneven pixels caused by the naive approach.

      • flags: Partial<CanvasModeOptions> = {}

      Returns void