melonJS
    Preparing search index...

    Class RenderTargetAbstract

    The base class of an offscreen render target: a surface the engine can draw into, clear, resize and read back, whatever the renderer.

    The one to create yourself is CanvasRenderTarget, a 2D canvas: draw something into it once (a texture, a background, a fog map) and reuse it every frame. The WebGL and WebGPU renderers keep render targets of their own for post effects (a framebuffer, a GPU texture); those are internal.

    Hierarchy (View Summary)

    Index
    height: number

    The height of this render target in pixels.

    width: number

    The width of this render target in pixels.

    • Creates a Blob object representing the image contained in this render target.

      Parameters

      • type: string = "image/png"

        a string indicating the image format (default "image/png")

      • Optionalquality: number

        a number between 0 and 1 for lossy formats (e.g. image/jpeg)

      Returns Promise<Blob>

      a Promise resolving to a Blob

    • Returns a data URL containing a representation of the current contents.

      Parameters

      • type: string = "image/png"

        a string indicating the image format (default "image/png")

      • Optionalquality: number

        a number between 0 and 1 for lossy formats (e.g. image/jpeg)

      Returns Promise<string>

      a Promise resolving to a data URL string

    • Read back pixel data from this render target.

      The portable form, and the one anything backend-agnostic should use. Synchronous readback is NOT portable: WebGPU can only map a buffer asynchronously, so its render targets cannot answer until a frame has been awaited. A CanvasRenderTarget also offers CanvasRenderTarget#getImageData, which answers at once.

      Parameters

      • Optionalx: number

        x coordinate of the top-left corner (default 0)

      • Optionaly: number

        y coordinate of the top-left corner (default 0)

      • Optionalwidth: number

        width of the area to read (default full width)

      • Optionalheight: number

        height of the area to read (default full height)

      Returns Promise<ImageData>

      the pixel data