mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 23:40:07 +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).
20 lines
778 B
GDScript
20 lines
778 B
GDScript
extends Node2D
|
|
|
|
@onready var viewport: SubViewport = $SubViewport
|
|
@onready var viewport_initial_size: Vector2i = viewport.size
|
|
@onready var viewport_sprite: Sprite2D = $ViewportSprite
|
|
|
|
|
|
func _ready() -> void:
|
|
$AnimatedSprite2D.play()
|
|
get_viewport().size_changed.connect(_root_viewport_size_changed)
|
|
|
|
|
|
# Called when the root's viewport size changes (i.e. when the window is resized).
|
|
# This is done to handle multiple resolutions without losing quality.
|
|
func _root_viewport_size_changed() -> void:
|
|
# The viewport is resized depending on the window height.
|
|
# To compensate for the larger resolution, the viewport sprite is scaled down.
|
|
viewport.size = Vector2.ONE * get_viewport().size.y
|
|
viewport_sprite.scale = Vector2.ONE * viewport_initial_size.y / get_viewport().size.y
|