QuadtreeSprite is a Starling extensions which enables efficient handling of large number of children DisplayObjects. It is useful when the game needs a container of objects which are usually not visible on the screen at the same time, such as large 2D world map.

The extension allows the addition and removal of objects in the same and usual Starling way, however the container must be updated every time one of its children change position or size. It’s possible to iterate through the currently visible objects or all of which the container holds.


// Define the world bounds, if objects is outside them it will always be displayed
var worldBounds:Rectangle = new Rectangle(...);
var container:QuadtreeSprite = new QuadtreeSprite(worldBounds);
// Adding/Removing children: same as in Starling:
container.addChild(new Quad(...));
var object:Quad = ...;
object.x = 10;
// Change visible elements
container.visibleViewport = new Rectangle(...);
// visible objects
for (var i:int = 0; i < container.numChildren; ++i) {
    var object:DisplayObject = container.getChildAt(i);
// all objects
for (var i:int = 0; i < container.dynamicNumChildren; ++i) {
    var object:DisplayObject = container.dynamicGetChildAt(i);
Misc . URL.