Jump to content

Take a screenshot of the canvas


Zaidar
 Share

Recommended Posts

Hi, 

 

do someone know how can I take a picture of the canvas ?

 

Usually with vanilla JS I would use canvas.toDataURL();

 

but here, when I try to access the canvas with game.canvas or game.stage.canvas, it just creates me a black image;

 

Ideas ?

 

Thanks.

Link to comment
Share on other sites

  • 3 months later...

Hi guys, finally the use of game.canvas.toDataUrl() works for me.

I'm using OOP on my games now, which I didn't do before. I don't know if it's from this or because the new phaser version (I was on 1.1.3, now 2.0.4), but it works perfectly with toDataUrl.

Be careful though, I like to develop my game for web browser, but also for Cocoonjs, and I don't think they support the toDataUrl as it's not in their HTML5 list of supported canvas function.

Link to comment
Share on other sites

  • 1 year later...

I learned now. We saw black picture. Because our games use WebGL as renderer. Canvas renderer is working perfectly.

 

Worth noting — now to support .png screenshots of WebGL rendered games, you can set a config parameter preserveDrawingBuffer that will let you call game.canvas.toDataURL() with WebGL or Canvas renderers with no issue.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...