virtualx-engine/demos/viewport/screen_capture/screen_capture.gd
Rémi Verschelde 8639cecf4c Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - space around weak operators (+, -), no space around strong operators (*, /)
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines

The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
2015-12-09 08:38:23 +01:00

16 lines
440 B
GDScript

extends Control
func _on_button_pressed():
get_viewport().queue_screen_capture()
# let two frames pass to make sure the screen was captured
yield(get_tree(),"idle_frame")
yield(get_tree(),"idle_frame")
# retrieve the captured image
var img = get_viewport().get_screen_capture()
# create a texture for it
var tex = ImageTexture.new()
tex.create_from_image(img)
# set it to the capture node
get_node("capture").set_texture(tex)