This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+3 votes

Hello. As in the game to take a screenshot?

in Engine by (346 points)

5 Answers

+4 votes
Best answer
# 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")
by (1,488 points)
selected by

Thanks for the help

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?

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 ...

+1 vote

I would refer you to Volzhs' answer here: https://godotengine.org/qa/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.

by (5,286 points)
0 votes

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

https://godotengine.org/download

by (370 points)
–3 votes

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

by (346 points)
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.