hbkmad Posted May 12, 2015 Share Posted May 12, 2015 Hello, I tried to make a screenshot of the game using game.canvas.toDataURL("image/png"); but the screenshot it returns me is a black one. Is there a property that I have to set before making the screenshot or something like that? Thanks. Link to comment Share on other sites More sharing options...
drhayes Posted May 12, 2015 Share Posted May 12, 2015 Are you using a WebGL renderer? Check out this thread. You might also be capturing at the wrong part of the render cycle. Check out this thread. Link to comment Share on other sites More sharing options...
hbkmad Posted May 13, 2015 Author Share Posted May 13, 2015 Thank you, the first topic helped me, I guess I'm using webGL. But now I have the data in Uint8Array how can I convert it to .png?Or is it better alternative to change my render to Canvas, how could I do that? Thank you again! Link to comment Share on other sites More sharing options...
drhayes Posted May 13, 2015 Share Posted May 13, 2015 AFAIK, if you have the pixels you can draw them to an offscreen canvas and toDataURL that one. Maybe I'm off-base. It depends... if you're just taking screenshots for, like, a review of your game then, sure, switch the renderer. The renderer is the third argument in your Phaser.Game constructor, e.g. "new Phaser.Game(800, 600, Phaser.CANVAS);" instead of "new Phaser.Game(800, 600, Phaser.AUTO);". Of course, those screenshots won't be able to do any WebGL stuff that you might be doing, like shaders and filters and stuff. But maybe that would work for you? Link to comment Share on other sites More sharing options...
hbkmad Posted May 13, 2015 Author Share Posted May 13, 2015 My idea is to have a stage where it would be like a "Wardrobe" where the player would choose different clothes and etc. on his character and when he's ready the screenshot would be send to a server where it will be used later for an avatar of this account. How do you think it will be best way to send the information about the screenshot to the server via AJAX ? I mean what type of data should I send and then convert it on Server- side and save it there. Can I send Uint8Array ? Thank you very much once again. Link to comment Share on other sites More sharing options...
drhayes Posted May 13, 2015 Share Posted May 13, 2015 You sure can send the UInt8Array. There's an overload of XMLHttpRequest#send that sends ArrayBufferViews... which is an alias-sort-of of UInt8Arrays. Link to comment Share on other sites More sharing options...
hbkmad Posted May 13, 2015 Author Share Posted May 13, 2015 Thank you very much for your help ! Link to comment Share on other sites More sharing options...
ForgeableSum Posted May 14, 2015 Share Posted May 14, 2015 For game.canvas.toDataURL in webgl, try setting preserveDrawingBuffer to true on your Phaser.Game. clark 1 Link to comment Share on other sites More sharing options...
Brian Jordan Posted October 13, 2015 Share Posted October 13, 2015 Worth noting—you must set preserveDrawingBuffer early on in the initialization sequence, it is now a game configuration parameter. Source: https://github.com/photonstorm/phaser/issues/987 Link to comment Share on other sites More sharing options...
Recommended Posts