ball_factory.gd 424 B

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