Zaidar Posted February 16, 2014 Share Posted February 16, 2014 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 More sharing options...
rich Posted February 16, 2014 Share Posted February 16, 2014 That is how you would do it - just make sure you do it at the right time or the canvas might have been cleared awaiting render. Link to comment Share on other sites More sharing options...
Zaidar Posted February 16, 2014 Author Share Posted February 16, 2014 Ok, I'll try to see that tomorrow, thx Link to comment Share on other sites More sharing options...
Ali BARIN Posted May 20, 2014 Share Posted May 20, 2014 I'm having same problem too. Does anyone have a suggestion? It doesn't work.window.open(game.canvas.toDataURL());Result: Link to comment Share on other sites More sharing options...
Ali BARIN Posted May 21, 2014 Share Posted May 21, 2014 I found a solution for this problem. I'm using html2canvas.js for solution. Use it for taking a screenshot:html2canvas(document.querySelector("canvas"), { onrendered: function(canvas){ window.open(canvas.toDataURL()); } }); Link to comment Share on other sites More sharing options...
themitchnz Posted May 21, 2014 Share Posted May 21, 2014 I've never done this, but I have bookmarked a couple of libraries: http://www.nihilogic.dk/labs/canvas2image/ - Still uses toDataUrl() but abstracts some of it away. https://github.com/spite/ccapture.js - This allows you to record canvas animation as a video. (not in real time) Link to comment Share on other sites More sharing options...
Zaidar Posted May 22, 2014 Author Share Posted May 22, 2014 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 More sharing options...
Ali BARIN Posted May 22, 2014 Share Posted May 22, 2014 Thank you all. I learned now. We saw black picture. Because our games use WebGL as renderer. Canvas renderer is working perfectly. Correct me if I'm wrong. Edit: I wrote wrong. I updated Link to comment Share on other sites More sharing options...
Zaidar Posted May 23, 2014 Author Share Posted May 23, 2014 I currently use Phaser.Canvas with my game and the toDataUrl() works perfectly, so I don't think the rendering Context is the issue. Link to comment Share on other sites More sharing options...
Brian Jordan Posted October 13, 2015 Share Posted October 13, 2015 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 More sharing options...
Recommended Posts