+3 votes

Hello. As in the game to take a screenshot?

in Engine by (341 points)

5 Answers

+4 votes
Best answer
# start 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
by (1,466 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()
$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,206 points)
0 votes

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


by (364 points)
–3 votes

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

by (341 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 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 webmaster@godotengine.org with your username.