0 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!

asked Aug 6 in Engine by ambrosecollector (18 points)

1 Answer

0 votes

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.

answered Aug 6 by njamster (9,824 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 How to use this Q&A? before posting your first questions.