Spawner.gd 530 B

12345678910111213141516171819202122232425
  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. print("spawn")
  9. var ball: PhysicsBody2D = Ball.instance()
  10. var dispersion = Vector2(randf() * dispersion_scale.x, randf() * dispersion_scale.y)
  11. ball.position = dispersion
  12. add_child(ball)
  13. get_tree().create_timer(delay).connect("timeout", self, "_on_delay_time_out")
  14. func _on_delay_time_out():
  15. spawn()