mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-06 16:00:08 +01:00
Improve the screen capture demo
This commit is contained in:
@@ -16,7 +16,7 @@ _global_script_class_icons={
|
||||
[application]
|
||||
|
||||
config/name="Screen Capture"
|
||||
run/main_scene="res://capture_screen.tscn"
|
||||
run/main_scene="res://screen_capture.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[debug]
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
extends Node
|
||||
|
||||
extends Control
|
||||
onready var captured_image = $CapturedImage
|
||||
|
||||
|
||||
func _ready():
|
||||
get_node("Button").connect("pressed", self, "_on_button_pressed");
|
||||
|
||||
|
||||
func _on_button_pressed():
|
||||
func _on_CaptureButton_pressed():
|
||||
get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME)
|
||||
# Let two frames pass to make sure the screen was captured
|
||||
# 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
|
||||
# Retrieve the captured image.
|
||||
var img = get_viewport().get_texture().get_data()
|
||||
|
||||
# Flip it on the y-axis (because it's flipped)
|
||||
# Flip it on the y-axis (because it's flipped).
|
||||
img.flip_y()
|
||||
|
||||
# Create a texture for it
|
||||
# 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)
|
||||
# Set the texture to the captured image node.
|
||||
captured_image.set_texture(tex)
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
[ext_resource path="res://screen_capture.gd" type="Script" id=1]
|
||||
[ext_resource path="res://mountains.png" type="Texture" id=2]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
[node name="ScreenCapture" type="Control"]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="BG" type="TextureRect" parent="."]
|
||||
[node name="Background" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 986.0
|
||||
@@ -18,7 +18,7 @@ grow_vertical = 0
|
||||
texture = ExtResource( 2 )
|
||||
expand = true
|
||||
|
||||
[node name="capture" type="TextureRect" parent="."]
|
||||
[node name="CapturedImage" type="TextureRect" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_right = 2013.0
|
||||
@@ -29,9 +29,10 @@ rect_scale = Vector2( 0.5, 0.5 )
|
||||
expand = true
|
||||
stretch_mode = 4
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
[node name="CaptureButton" type="Button" parent="."]
|
||||
margin_left = 48.0
|
||||
margin_top = 53.0
|
||||
margin_right = 188.0
|
||||
margin_bottom = 113.0
|
||||
text = "Capture screen"
|
||||
[connection signal="pressed" from="CaptureButton" to="." method="_on_CaptureButton_pressed"]
|
||||
Reference in New Issue
Block a user