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!
protected var _canSubdivide:Boolean
Whether this branch of the tree can be subdivided or not.
protected var _headA:FlxList
These variables refer to the internal A and B linked lists,
which are used to store objects in the leaves.
protected var _headB:FlxList
protected static var _min:uint
These variables refer to the potential child quadrants for this node.
protected var _ne:FlxQuadTree
protected var _nw:FlxQuadTree
protected static var _o:FlxObject
These objects are used to reduce recursive parameters internally.
protected static var _oa:uint
protected static var _ob:Number
protected static var _oc:Function
protected static var _ol:Number
protected static var _or:Number
protected static var _ot:Number
protected var _se:FlxQuadTree
protected var _sw:FlxQuadTree
protected var _tailA:FlxList
protected var _tailB:FlxList
public function FlxQuadTree(X:Number, Y:Number, Width:Number, Height:Number, Parent:FlxQuadTree = null)
Instantiate a new Quad Tree node.
Parameters | X:Number — The X-coordinate of the point in space.
|
|
| Y:Number — The Y-coordinate of the point in space.
|
|
| Width:Number — Desired width of this node.
|
|
| Height:Number — Desired height of this node.
|
|
| Parent:FlxQuadTree (default = null ) — The parent branch or node. Pass null to create a root.
|
public function add(Object:FlxObject, List:uint):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
| Object:FlxObject — The FlxObject you want to add. FlxGroup objects will be recursed and their applicable members added automatically.
|
|
| List:uint — A uint flag indicating the list to which you want to add the objects. Options are A_LIST and B_LIST .
|
protected function addObject():void
Internal function for recursively navigating and creating the tree
while adding objects to the appropriate nodes.
protected function addToList():void
Internal function for recursively adding objects to leaf lists.
public function overlap(BothLists:Boolean = true, Callback:Function = null):Boolean
FlxQuadTree
's other main function. Call this after adding objects
using FlxQuadTree.add()
to compare the objects that you loaded.
Parameters
| BothLists:Boolean (default = true ) — Whether you are doing an A-B list comparison, or comparing A against itself.
|
|
| Callback:Function (default = null ) — A function with two FlxObject parameters - e.g. myOverlapFunction(Object1:FlxObject,Object2:FlxObject); If no function is provided, FlxQuadTree will call kill() on both objects.
|
Returns | Boolean — Whether or not any overlaps were found.
|
protected function overlapNode(Iterator:FlxList = null):Boolean
An internal function for comparing an object against the contents of a node.
Parameters
| Iterator:FlxList (default = null ) — An optional pointer to a linked list entry (for comparing A against itself).
|
Returns | Boolean — Whether or not any overlaps were found.
|
public static const A_LIST:uint = 0
Flag for specifying that you want to add an object to the A list.
public static const B_LIST:uint = 1
Flag for specifying that you want to add an object to the B list.
Sun Apr 17 2011, 12:17 AM -07:00