Spawner.gd 542 B

123456789101112131415161718192021222324
  1. extends Position2D
  2. var Ball: PackedScene = preload("res://labs/cascade/component/ball/Ball.tscn")
  3. export(Vector2) var dispersion_scale = Vector2.ONE
  4. export(float) var delay = 1
  5. func _ready():
  6. spawn()
  7. func spawn():
  8. var ball: PhysicsBody2D = Ball.instance()
  9. var dispersion = Vector2(rand_range(-1.0, 1.0) * dispersion_scale.x, rand_range(-1.0, 1.0) * dispersion_scale.y)
  10. ball.position = dispersion
  11. add_child(ball)
  12. get_tree().create_timer(delay).connect("timeout", self, "_on_delay_time_out")
  13. func _on_delay_time_out():
  14. spawn()