A fairly generic quad tree structure for rapid overlap checks. FlxQuadTree is also configured for single or dual list operation. You can add items either to its A list or its B list. When you do an overlap check, you can compare the A list to itself, or the A list against the B list. Handy for different things!
Static variables
staticinlineread onlyA_LIST:Int = 0
Flag for specifying that you want to add an object to the A list.
staticinlineread onlyB_LIST:Int = 1
Flag for specifying that you want to add an object to the B list.
static_NUM_CACHED_QUAD_TREES:Int = 0
Pooling mechanism, turn FlxQuadTree into a linked list, when FlxQuadTrees are destroyed, they get added to the list, and when they get recycled they get removed.
Static methods
staticclearCache():Void
Clear cached Quad Tree nodes. You might want to do this when loading new levels (probably not though, no need to clear cache unless you run into memory problems).
staticrecycle(X:Float, Y:Float, Width:Float, Height:Float, ?Parent:FlxQuadTree):FlxQuadTree
Recycle a cached Quad Tree node, or creates a new one if needed.
Parameters:
X | The X-coordinate of the point in space. |
---|---|
Y | The Y-coordinate of the point in space. |
Width | Desired width of this node. |
Height | Desired height of this node. |
Parent | The parent branch or node. Pass null to create a root. |
Variables
Methods
add(ObjectOrGroup:FlxBasic, list:Int):Void
Call this function to add an object to the root of the tree. This function will recursively add all group members, but not the groups themselves.
Parameters:
ObjectOrGroup | FlxObjects are just added, FlxGroups are recursed and their applicable members added accordingly. |
---|---|
List | A int flag indicating the list to which you want to add the objects. Options are A_LIST and B_LIST. |
execute():Bool
FlxQuadTree's other main function. Call this after adding objects using FlxQuadTree.load() to compare the objects that you loaded.
Returns:
Whether or not any overlaps were found.
load(ObjectOrGroup1:FlxBasic, ?ObjectOrGroup2:FlxBasic, ?NotifyCallback:(FlxObject, FlxObject) ‑> Void, ?ProcessCallback:(FlxObject, FlxObject) ‑> Bool):Void
Load objects and/or groups into the quad tree, and register notify and processing callbacks.
Parameters:
ObjectOrGroup1 | Any object that is or extends FlxObject or FlxGroup. |
---|---|
ObjectOrGroup2 | Any object that is or extends FlxObject or FlxGroup. If null, the first parameter will be checked against itself. |
NotifyCallback | A function with the form myFunction(Object1:FlxObject,Object2:FlxObject):void that is called whenever two objects are found to overlap in world space, and either no ProcessCallback is specified, or the ProcessCallback returns true. |
ProcessCallback | A function with the form myFunction(Object1:FlxObject,Object2:FlxObject):Boolean that is called whenever two objects are found to overlap in world space. The NotifyCallback is only called if this function returns true. See FlxObject.separate(). |