Take screen screen capture of a portion(Phaser3)

This article can be read in about 2 minutes.
PR

The purpose 

Take a screen capture (snapshot) of the Phaser3 display

Background

I tried get an Image from a Canvas element, but I couldn’t get a 2D context, so I looked for another method.

PR

Implementation

Call the following function in any scene.

this.game.renderer.snapshotArea(x, y, width, height, callback);

x and y represent the coordinates of the top-left corner of the display area.

(The red area in the diagram below shows the captured region.)

The callback’s argument is an Image element.

For example, you would set a function like this as the callback:

(A capture of the screen displayed in Phaser3 is shown at the bottom of the HTML.)

(image) =>{
    document.body.append(image) 
}
PR

Result

We are able to output the screen displayed in Phaser3 as an image.

The image format is PNG (changeable). 

PR

Reference

Snapshot - Notes of Phaser 3

comment

Copied title and URL