slot_array.gd 751 B

1234567891011121314151617181920212223242526272829
  1. @tool
  2. extends Node2D
  3. @export var count = 1:
  4. set(value):
  5. count = value
  6. redraw()
  7. @export var separation = 200:
  8. set(value):
  9. separation = value
  10. redraw()
  11. @export var particles: PackedScene:
  12. set(value):
  13. particles = value
  14. redraw()
  15. func redraw():
  16. for n in get_children():
  17. remove_child(n)
  18. if particles != null:
  19. var start_pos = 0.0
  20. if count % 2 == 1:
  21. start_pos = -floor(count / 2.0) * separation
  22. else:
  23. start_pos = (-(count / 2.0) + 0.5) * separation
  24. for i in range(0, count):
  25. var child = particles.instantiate()
  26. child.set_position(Vector2(start_pos + i * separation, 0))
  27. add_child(child)