mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 15:00:09 +01:00
This leads to code that is easier to understand and runs faster thanks to GDScript's typed instructions. The untyped declaration warning is now enabled on all projects where type hints were added. All projects currently run without any untyped declration warnings. Dodge the Creeps and Squash the Creeps demos intentionally don't use type hints to match the documentation, where type hints haven't been adopted yet (given its beginner focus).
24 lines
703 B
GDScript
24 lines
703 B
GDScript
extends Node
|
|
|
|
@onready var captured_image: TextureRect = $CapturedImage
|
|
@onready var capture_button: Button = $CaptureButton
|
|
|
|
|
|
func _ready() -> void:
|
|
# Focus button for keyboard/gamepad-friendly navigation.
|
|
capture_button.grab_focus()
|
|
|
|
|
|
func _on_capture_button_pressed() -> void:
|
|
# Retrieve the captured image.
|
|
var img := get_viewport().get_texture().get_image()
|
|
|
|
# Create a texture for it.
|
|
var tex := ImageTexture.create_from_image(img)
|
|
|
|
# Set the texture to the captured image node.
|
|
captured_image.set_texture(tex)
|
|
|
|
# Colorize the button with a random color, so you can see which button belongs to which capture.
|
|
capture_button.modulate = Color.from_hsv(randf(), randf_range(0.2, 0.8), 1.0)
|