The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+2 votes

As part of my game's saving system, I want to take a screenshot of an area, minus certain sprites, and minus the controls, for use as the save's thumbnail.

When the game is saving, the screen will be on a menu screen, which I could do as a canvaslayer, or however else it makes sense given what i want to do. I know how to set all of the things I want to be visible or invisible appropriately, and know how to take a screenshot, I just don't know how to do it in a way that the player won't see a few frames of the game looking wrong, without the GUI and certain other graphical elements.

I tried setting everything invisible, taking the screenshot, and setting it as visible again within the same frame, but, as I expected, it captures the frame that is currently displayed when the process starts, and so it captured a normal frame.

Thank you for your help!

in Engine by (20 points)

1 Answer

+1 vote

I don't know if there is a simpler way to achieve this, but you certainly should be able to create two separate Viewport-nodes (one holding the stuff you want to screenshot, the other one holding the stuff you want to meanwhile show to the player), have the latter one on top and then only take the texture of the former Viewport.

by (10,634 points)

This is a good idea, but some of the sprites I don't want to capture are part of the normal game physicics, and I believe that things in different viewports don't interact with one another (unless I'm mistaken, which is absolutely possible).

The more I've read about since posting this question, the more I think that viewports are the key, though. I've tried creating a viewport which is not in a container, setting its world to the main world with

get_node('Screenshot_Port').world_2d = get_viewport().world_2d

and then, after a .5 second timer to make sure I'm picking up a populated frame, I screenshot that viewport, but ithe screencap just gives me a blank image (I export the image as a png, to see what the screenshot captured). There's a camera in the viewport that is set to current, and the view I'm trying to capture will always be at (0, 0), so I'm not sure why it's not picking anything up.

(The viewport has the standard settings, except that the size is 1280×720, ownworld = true, usage is 2d, vflip = true, and update mode is always)

Thank you for your help! I know this is a little complicalted.

some of the sprites I don't want to capture are part of the normal game physicics

You could hide those, take the screenshot and then make them visible again. As long as there is a second viewport on top of it, the players won't notice. And judging from your description, you could simply turn the menu screen into a separate viewport.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.