melonJS
    Preparing search index...

    Class CanvasRenderTarget

    A 2D canvas render target for offscreen texture generation. Used by Text, Gradient, Light2d and Particle systems to render into a canvas that is then uploaded as a WebGL texture.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • width: number

        the desired width of the canvas

      • height: number

        the desired height of the canvas

      • attributes: {
            antiAlias?: boolean;
            context?: string;
            offscreenCanvas?: boolean;
            preferWebGL1?: boolean;
            transparent?: boolean;
            willReadFrequently?: boolean;
        } = defaultAttributes

        The attributes to create both the canvas and context

        • OptionalantiAlias?: boolean

          Whether to enable anti-aliasing, use false (default) for a pixelated effect.

        • Optionalcontext?: string

          the context type to be created ("2d", "webgl")

        • OptionaloffscreenCanvas?: boolean

          will create an offscreenCanvas if true instead of a standard canvas

        • OptionalpreferWebGL1?: boolean

          set to true for force using WebGL1 instead of WebGL2 (if supported)

        • Optionaltransparent?: boolean

          specify if the canvas contains an alpha channel

        • OptionalwillReadFrequently?: boolean

          Indicates whether or not a lot of read-back operations are planned

      Returns CanvasRenderTarget

    Properties

    attributes: {
        antiAlias: boolean;
        blendMode: string;
        context: string;
        failIfMajorPerformanceCaveat: boolean;
        offscreenCanvas: boolean;
        powerPreference: string;
        preferWebGL1: boolean;
        premultipliedAlpha: boolean;
        stencil: boolean;
        transparent: boolean;
        willReadFrequently: boolean;
    } & {
        antiAlias?: boolean;
        context?: string;
        offscreenCanvas?: boolean;
        preferWebGL1?: boolean;
        transparent?: boolean;
        willReadFrequently?: boolean;
    }
    canvas: any
    context: any
    glTextureUnit: any
    WebGLVersion: any

    Accessors

    Methods

    • Returns an ImageData object representing the underlying pixel data for a specified portion of this canvas texture. (Note: when using getImageData(), it is highly recommended to use the willReadFrequently attribute when creatimg the corresponding canvas texture)

      Parameters

      • x: number

        The x-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted

      • y: number

        The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted

      • width: number

        The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left

      • height: number

        The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up

      Returns ImageData

      The ImageData extracted from this CanvasRenderTarget.

    • Creates a Blob directly from the canvas (avoids the getImageData round-trip).

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A number between 0 and 1 for lossy formats (image/jpeg, image/webp)

      Returns Promise<Blob>

      A Promise resolving to a Blob

    • Returns a data URL directly from the canvas (avoids the getImageData/Blob round-trip). Note: not supported by OffscreenCanvas — falls back to the base implementation.

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A number between 0 and 1 for lossy formats (image/jpeg, image/webp)

      Returns Promise<string>

      A Promise resolving to a data URL string