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).
18 lines
480 B
GDScript
18 lines
480 B
GDScript
extends Node2D
|
|
|
|
@export var ball_scene: PackedScene = preload("res://ball.tscn")
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_echo():
|
|
return
|
|
|
|
if event is InputEventMouseButton and event.is_pressed():
|
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
|
spawn(get_global_mouse_position())
|
|
|
|
|
|
func spawn(spawn_global_position: Vector2) -> void:
|
|
var instance: Node2D = ball_scene.instantiate()
|
|
instance.global_position = spawn_global_position
|
|
add_child(instance)
|