Skip to content

snapshotCanvas function bug in CanvasRenderer #5792

@rollinsafary-inomma

Description

@rollinsafary-inomma

Version

  • Phaser Version: 3.55.2
  • Operating system: doesn't matter
  • Browser: doesn't matter

Description

Trying to get a snapshot from the container, when using Canvas Renderer. There seems a reference issue.

    snapshotCanvas: function (canvas, callback, getPixel, x, y, width, height, type, encoderOptions)
    {
        if (getPixel === undefined) { getPixel = false; }

        this.snapshotArea(x, y, width, height, callback, type, encoderOptions);

        var state = this.snapshotState;

        state.getPixel = getPixel;

        CanvasSnapshot(this.canvas, state);

        state.callback = null;

        return this;
    },

The function uses CanvasSnapshot(this.canvas, state); but there is no this.canvas property in there, there is canvas argument, that I think might be there or this.gameCanvas could be placed instead of this.canvas.

Example Test Code

  protected async generateImage(): Promise<
    Phaser.Display.Color | HTMLImageElement
  > {
    return new Promise<Phaser.Display.Color | HTMLImageElement>((resolve) => {
      const texture = this.add.renderTexture(
        0,
        0,
        this.gameObject.width,
        this.gameObject.height,
      );
      texture.draw(this.gameObject);
      texture.snapshot(resolve, 'image/png', 1);
    });
  }
}

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions