screen_capture.gd 442 B

1234567891011121314151617
  1. extends Control
  2. func _on_button_pressed():
  3. get_viewport().queue_screen_capture()
  4. # Let two frames pass to make sure the screen was captured
  5. yield(get_tree(), "idle_frame")
  6. yield(get_tree(), "idle_frame")
  7. # Retrieve the captured image
  8. var img = get_viewport().get_screen_capture()
  9. # Create a texture for it
  10. var tex = ImageTexture.new()
  11. tex.create_from_image(img)
  12. # Set it to the capture node
  13. get_node("capture").set_texture(tex)