Empty image - todataurl()

Hi! I am trying to download my canvas as an image.
My code:

function saveImage() { var download = document.getElementById("saveImage"); var image = game.config.canvas.toDataURL(); download.setAttribute("href", image); download.setAttribute("download", "archive.png"); }

html:
<a class="nav-link" onclick="saveImage()" id="saveImage">Save image</a>

and the downloaded picture is empty. Why?
What can i do?

I just did some simple tests with game.canvas.toDataURL() and it seems that the only way to have this function work is if Phaser is in CANVAS mode.
Otherwise it only shows an empty black image.

You can try to force Phaser to CANVAS mode.

1 Like

I see! This is my solution! Thank you for your answear!
For webgl i used in config this option preserveDrawingBuffer:true.

Nice option, I didn’t know about that. Thank you very much!