class flixel.system.FlxQuadTree extends FlxRect

Available on all platforms

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!

Class Fields

static var A_LIST:Int

Flag for specifying that you want to add an object to the A list.

static var B_LIST:Int

Flag for specifying that you want to add an object to the B list.

static var _NUM_CACHED_QUAD_TREES:Int

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 var divisions:Int

Controls the granularity of the quad tree. Default is 6 (decent performance on large and small worlds).

static function clearCache():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).

static function recycle(X:Float, Y:Float, Width:Float, Height:Float, ?Parent:FlxQuadTree = null):FlxQuadTree

Recycle a cached Quad Tree node, or creates a new one if needed. *

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.

Instance Fields

function 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. *

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 ALIST and BLIST.

function destroy():Void

Clean up memory.

function 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.

function load(ObjectOrGroup1:FlxBasic, ?ObjectOrGroup2:FlxBasic = null, ?NotifyCallback:FlxObject ->FlxObject ->Void = null, ?ProcessCallback:FlxObject ->FlxObject ->Bool = null):Void

Load objects and/or groups into the quad tree, and register notify and processing callbacks. *

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().

function reset(X:Float, Y:Float, Width:Float, Height:Float, ?Parent:FlxQuadTree = null):Void