Take a screenshot and save it to a .png file

1 vote · 0 comments

It may be useful to take screenshot of the game and save it to a file.

I use this when a error is detected and dump the error + screenshot to a logs/ directory as well as trying to upload it to an FTP server.

raw ·
copy
· download
image = MOAIImage.new() -- image to store the screenshot in frameBuffer = MOAIFrameBufferTexture.new() frameBuffer:setRenderTable({layer1, layer2}) -- layers of your game. You can omit layers if you don't want them to be part of the screenshot. frameBuffer:init(screenWidth, screenHeight) MOAIRenderMgr.setBufferTable({frameBuffer}) frameBuffer:grabNextFrame(image, function() -- callback function run once the image has been filled with the screenshot image:writePNG("screenshot.png") -- writes the image in memory to a file end) -- Alternatively if you do not have access to your screen resolution and all layers this works just the same, but this method may produce errors: -- "Attempt to access MOAILuaObject userdata tagged for garbage collection; running a full cycle of GC prior to reallocation." -- It still produces the screenshots in my experience though, just a warning image = MOAIImage.new() -- image to store the screenshot in frameBuffer = MOAIGfxDevice.getFrameBuffer() MOAIRenderMgr.setBufferTable({frameBuffer}) frameBuffer:grabNextFrame(image, function() -- callback function run once the image has been filled with the screenshot image:writePNG("screenshot.png") -- writes the image in memory to a file end)

Be the first to comment

Sign in with OpenID