test_stack.gd 860 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. extends Test
  2. @export var height = 10
  3. @export var width = 1
  4. @export var box_size = Vector2(40.0, 40.0)
  5. @export var box_spacing = Vector2(0.0, 0.0)
  6. func _ready():
  7. _create_stack()
  8. func _create_stack():
  9. var root_node = $Stack
  10. var template_body = create_rigidbody_box(box_size, true)
  11. var pos_y = -0.5 * box_size.y - box_spacing.y
  12. for level in height:
  13. var row_node = Node2D.new()
  14. row_node.position = Vector2(0.0, pos_y)
  15. row_node.name = "Row%02d" % (level + 1)
  16. root_node.add_child(row_node)
  17. var pos_x = -0.5 * (width - 1) * (box_size.x + box_spacing.x)
  18. for box_index in range(width):
  19. var box = template_body.duplicate()
  20. box.position = Vector2(pos_x, 0.0)
  21. box.name = "Box%02d" % (box_index + 1)
  22. row_node.add_child(box)
  23. pos_x += box_size.x + box_spacing.x
  24. pos_y -= box_size.y + box_spacing.y
  25. template_body.queue_free()