ball_factory.gd 480 B

123456789101112131415161718
  1. extends Node2D
  2. @export var ball_scene: PackedScene = preload("res://ball.tscn")
  3. func _unhandled_input(event: InputEvent) -> void:
  4. if event.is_echo():
  5. return
  6. if event is InputEventMouseButton and event.is_pressed():
  7. if event.button_index == MOUSE_BUTTON_LEFT:
  8. spawn(get_global_mouse_position())
  9. func spawn(spawn_global_position: Vector2) -> void:
  10. var instance: Node2D = ball_scene.instantiate()
  11. instance.global_position = spawn_global_position
  12. add_child(instance)