melonjs
    Preparing search index...

    Class CanvasTexture

    since 17.1.0

    CanvasRenderTarget

    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?: boolean;
            offscreenCanvas?: boolean;
            willReadFrequently?: boolean;
        }

        The attributes to create both the canvas and context

        • OptionalantiAlias?: boolean

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

        • Optionalcontext?: boolean

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

        • OptionaloffscreenCanvas?: boolean

          will create an offscreenCanvas if true instead of a standard canvas

        • OptionalwillReadFrequently?: boolean

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

      Returns CanvasTexture

    Properties

    the rendering context of this CanvasRenderTarget

    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 object representing the image contained in this canvas texture

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning a Blob object representing the image contained in this canvas texture

      renderTarget.convertToBlob().then((blob) => console.log(blob));
      
    • returns a data URL containing a representation of the most recently rendered image of this canvas texture (not supported by OffscreenCanvas)

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning a string containing the requested data URL.

      renderer.toDataURL().then((dataURL) => console.log(dataURL));
      
    • creates an ImageBitmap object from the most recently rendered image of this canvas texture

      Parameters

      • Optionaltype: string = "image/png"

        A string indicating the image format

      • Optionalquality: number

        A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

      Returns Promise<any>

      A Promise returning an ImageBitmap.

      renderTarget.transferToImageBitmap().then((bitmap) => console.log(bitmap));