File tree Expand file tree Collapse file tree 3 files changed +15
-18
lines changed Expand file tree Collapse file tree 3 files changed +15
-18
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ _global_script_class_icons={
1616[application ]
1717
1818config/name ="Screen Capture"
19- run/main_scene ="res://capture_screen .tscn"
19+ run/main_scene ="res://screen_capture .tscn"
2020config/icon ="res://icon.png"
2121
2222[debug ]
Original file line number Diff line number Diff line change 1+ extends Node
12
2- extends Control
3+ onready var captured_image = $ CapturedImage
34
4-
5- func _ready ():
6- get_node ("Button" ).connect ("pressed" , self , "_on_button_pressed" );
7-
8-
9- func _on_button_pressed ():
5+ func _on_CaptureButton_pressed ():
106 get_viewport ().set_clear_mode (Viewport .CLEAR_MODE_ONLY_NEXT_FRAME )
11- # Let two frames pass to make sure the screen was captured
7+ # Let two frames pass to make sure the screen was captured.
128 yield (get_tree (), "idle_frame" )
139 yield (get_tree (), "idle_frame" )
1410
15- # Retrieve the captured image
11+ # Retrieve the captured image.
1612 var img = get_viewport ().get_texture ().get_data ()
1713
18- # Flip it on the y-axis (because it's flipped)
14+ # Flip it on the y-axis (because it's flipped).
1915 img .flip_y ()
2016
21- # Create a texture for it
17+ # Create a texture for it.
2218 var tex = ImageTexture .new ()
2319 tex .create_from_image (img )
2420
25- # Set it to the capture node
26- get_node ( "capture" ) .set_texture (tex )
21+ # Set the texture to the captured image node.
22+ captured_image .set_texture (tex )
Original file line number Diff line number Diff line change 33[ext_resource path ="res://screen_capture.gd" type ="Script" id =1 ]
44[ext_resource path ="res://mountains.png" type ="Texture" id =2 ]
55
6- [node name ="Control " type ="Control" ]
6+ [node name ="ScreenCapture " type ="Control" ]
77margin_right = 40.0
88margin_bottom = 40.0
99script = ExtResource ( 1 )
1010
11- [node name ="BG " type ="TextureRect" parent ="." ]
11+ [node name ="Background " type ="TextureRect" parent ="." ]
1212anchor_right = 1.0
1313anchor_bottom = 1.0
1414margin_right = 986.0
@@ -18,7 +18,7 @@ grow_vertical = 0
1818texture = ExtResource ( 2 )
1919expand = true
2020
21- [node name ="capture " type ="TextureRect" parent ="." ]
21+ [node name ="CapturedImage " type ="TextureRect" parent ="." ]
2222anchor_right = 1.0
2323anchor_bottom = 1.0
2424margin_right = 2013.0
@@ -29,9 +29,10 @@ rect_scale = Vector2( 0.5, 0.5 )
2929expand = true
3030stretch_mode = 4
3131
32- [node name ="Button " type ="Button" parent ="." ]
32+ [node name ="CaptureButton " type ="Button" parent ="." ]
3333margin_left = 48.0
3434margin_top = 53.0
3535margin_right = 188.0
3636margin_bottom = 113.0
3737text = "Capture screen"
38+ [connection signal ="pressed" from ="CaptureButton" to ="." method ="_on_CaptureButton_pressed" ]
You can’t perform that action at this time.
0 commit comments