Recalculate Container Bounds when Removing Children

What would be the best way to adjust the size and bounds of the body of a Container, when removing one of its children?

I can iterate over the children to figure out where the bounds are, before and after I remove a child, but I need to update the container’s position, width and height. Is there an existing method that will recalculate/adjust this already?

A container has a getBounds() method that calculates the bounds of all the children. A new bounds rectangle is calculate and returned each time the method is called. So, call getBounds() each time you remove a child, and reposition the container based on the new values.

I’m not sure about manually setting the width, height of the container. I guess it depends on what you’re trying to get done.

I’m using a container to hold rows and columns of sprites that are the same size.
I need to adjust the body of the container whenever sprites are removed, specifically when a row or column on the perimeter of the container effectively becomes ‘empty’. This container collides with the world boundaries of the scene.

I mostly have this working now. Whenever I’m about to remove a child from the container I store the before bounds and min/max coords for children in the container, and then compare that with the bounds & min/max after its removed (depending upon where a column/row is being removed). I have to adjust the width or height of the container and the offset of its body, whenever a column or row is removed.