Phaser API Documentation

  Version: 
snapshotFramebuffer(framebuffer, bufferWidth, bufferHeight, callback, [getPixel], [x], [y], [width], [height], [type], [encoderOptions])

Description:

Takes a snapshot of the given area of the given frame buffer.

Unlike the other snapshot methods, this one is processed immediately and doesn't wait for the next render.

Snapshots work by using the WebGL readPixels feature to grab every pixel from the frame buffer into an ArrayBufferView. It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

Parameters:

name type arguments Default description
framebuffer WebGLFramebuffer

The framebuffer to grab from.

bufferWidth number

The width of the framebuffer.

bufferHeight number

The height of the framebuffer.

callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

The Function to invoke after the snapshot image is created.

getPixel boolean <optional> false

Grab a single pixel as a Color object, or an area as an Image object?

x number <optional> 0

The x coordinate to grab from.

y number <optional> 0

The y coordinate to grab from.

width number <optional> bufferWidth

The width of the area to grab.

height number <optional> bufferHeight

The height of the area to grab.

type string <optional> 'image/png'

The format of the image to create, usually image/png or image/jpeg.

encoderOptions number <optional> 0.92

The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg.

Returns:
Description:

This WebGL Renderer.

Examples:
Since: 3.19.0