Files
godot-demo-projects/2d/instancing/ball_factory.gd
Hugo Locurcio bac1e69164 Use static typing in all demos (#1063)
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).
2024-06-01 12:12:18 +02:00

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)