As in the game to take a screenshot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tort
:warning: Old Version Published before Godot 3 was released.

Hello. As in the game to take a screenshot?

:bust_in_silhouette: Reply From: lukas
:bust_in_silhouette: Reply From: avencherus

I would refer you to Volzhs’ answer here: https://forum.godotengine.org/3313/capture-frame-and-show-it-as-sprite

You need to yield an idle frame or defer, since the request isn’t fulfilled until the next frame.

:bust_in_silhouette: Reply From: guppy42

In the examples viewport/screen_capture there is a complete example you can study, get them here;

:bust_in_silhouette: Reply From: Tort

Maybe I do not understand the question put. Screen I need to save in image.png.

:bust_in_silhouette: Reply From: jospic



# start screen capture
get_viewport().queue_screen_capture()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")

# get screen capture
var capture = get_viewport().get_screen_capture()
# save to a file
capture.save_png("user://screenshot.png")

Thanks for the help

Tort | 2017-02-09 14:56

If I try to use this code, I get the error message:

Invalid call: Nonexistent function 'queue_screen_capture' in base 'Viewport'.

I’m using Godot v.3.1. How can I get this code to work?

Lukas8993 | 2019-09-07 19:37

queue_screen_capture() and get_screen_capture() don’t even exist in Godot 3.x

Try with this:

var img = get_viewport().get_texture().get_data()
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
var tex = ImageTexture.new()
tex.create_from_image(img)
$sprite.texture = tex

But I haven’t tried yet …

jospic | 2019-09-09 09:17