Skip to main content
Version: Phaser v4.0.0

Phaser.Renderer.Snapshot

Scope: static

Source: src/renderer/snapshot/index.js#L7

Static functions

Canvas

<static> Canvas(canvas, config)

Description:

Takes a snapshot of the current frame displayed by a canvas. Depending on the configuration, this can operate in one of three modes: single-pixel color sampling, partial area capture, or full canvas capture.

In pixel mode, the color at the given (x, y) coordinate is read and the callback is invoked immediately with a Phaser.Display.Color object.

In area or full capture mode, the relevant region is encoded as a data URL and assigned to a new Image object. Once the image has loaded, the callback provided in the Snapshot Configuration object is invoked with the Image as its argument. If the image fails to load, the callback is still invoked but with no argument.

Parameters:

nametypeoptionaldescription
canvasHTMLCanvasElementNoThe canvas to take a snapshot of.
configPhaser.Types.Renderer.Snapshot.SnapshotStateNoThe snapshot configuration object.

Source: src/renderer/snapshot/CanvasSnapshot.js#L11
Since: 3.0.0


WebGL

<static> WebGL(sourceContext, config)

Description:

Takes a snapshot of an area from the current frame displayed by a WebGL canvas, or reads the color value of a single pixel, depending on the getPixel property of the snapshot configuration object.

When capturing an area, the raw pixel data is read from the WebGL context and composited into a temporary canvas, accounting for WebGL's inverted Y-axis and optionally reversing pre-multiplied alpha. The canvas is then serialized to a data URL and loaded into an Image object, which is passed to the callback defined in the Snapshot Configuration object once loading completes.

When reading a single pixel, the RGBA values at the given coordinates are read directly via gl.readPixels and returned as a Phaser.Display.Color object via the callback.

Parameters:

nametypeoptionaldescription
sourceContextWebGLRenderingContextNoThe WebGL context to take a snapshot of.
configPhaser.Types.Renderer.Snapshot.SnapshotStateNoThe snapshot configuration object.

Source: src/renderer/snapshot/WebGLSnapshot.js#L11
Since: 3.0.0