I'm using Cocos2d-x and I'm just looking for efficient way to remove sprites under some rectangular region.
For example if I have a lot of random located sprites on the scene and I want to remove all of them if they belong to rectangular (x1, y1),(x2, y2), then what I need to do?
I see that there are two ways to remove sprite from the scene:
The only way to do this using default cocos functionality would be to iterate over each child detect overlapping and remove nodes that match criteria.
removeFromParent() as well as
removeChildByTag() will invoke
Vector of child nodes. With complexity O(n). So first step of optimization would be to use
detachChild that utilizes index of child.
But if that is not fast enough I would recommend using special data structure to quickly search for overlapping like interval tree.