Packageorg.flixel.system
Classpublic class FlxQuadTree
InheritanceFlxQuadTree Inheritance FlxRect Inheritance Object

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!



Public Properties
 PropertyDefined By
 Inheritedbottom : Number
[read-only] The Y coordinate of the bottom of the rectangle.
FlxRect
  divisions : uint
[static] Controls the granularity of the quad tree.
FlxQuadTree
 Inheritedheight : Number
FlxRect
 Inheritedleft : Number
[read-only] The X coordinate of the left side of the rectangle.
FlxRect
 Inheritedright : Number
[read-only] The X coordinate of the right side of the rectangle.
FlxRect
 Inheritedtop : Number
[read-only] The Y coordinate of the top of the rectangle.
FlxRect
 Inheritedwidth : Number
FlxRect
 Inheritedx : Number
FlxRect
 Inheritedy : Number
FlxRect
Protected Properties
 PropertyDefined By
  _bottomEdge : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _canSubdivide : Boolean
Whether this branch of the tree can be subdivided or not.
FlxQuadTree
  _checkObjectHullHeight : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _checkObjectHullWidth : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _checkObjectHullX : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _checkObjectHullY : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _halfHeight : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _halfWidth : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _headA : FlxList
Refers to the internal A and B linked lists, which are used to store objects in the leaves.
FlxQuadTree
  _headB : FlxList
Refers to the internal A and B linked lists, which are used to store objects in the leaves.
FlxQuadTree
  _iterator : FlxList
[static] Internal, used during tree processing and overlap checks.
FlxQuadTree
  _leftEdge : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _list : uint
[static] Internal, used during tree processing and overlap checks.
FlxQuadTree
  _midpointX : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _midpointY : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _min : uint
[static] Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _northEastTree : FlxQuadTree
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _northWestTree : FlxQuadTree
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _notifyCallback : Function
[static] Internal, used during tree processing and overlap checks.
FlxQuadTree
  _object : FlxObject
[static] Internal, used to reduce recursive method parameters during object placement and tree formation.
FlxQuadTree
  _objectBottomEdge : Number
[static] Internal, used to reduce recursive method parameters during object placement and tree formation.
FlxQuadTree
  _objectHullHeight : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _objectHullWidth : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _objectHullX : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _objectHullY : Number
[static] Internal, helpers for comparing actual object-to-object overlap - see overlapNode().
FlxQuadTree
  _objectLeftEdge : Number
[static] Internal, used to reduce recursive method parameters during object placement and tree formation.
FlxQuadTree
  _objectRightEdge : Number
[static] Internal, used to reduce recursive method parameters during object placement and tree formation.
FlxQuadTree
  _objectTopEdge : Number
[static] Internal, used to reduce recursive method parameters during object placement and tree formation.
FlxQuadTree
  _processingCallback : Function
[static] Internal, used during tree processing and overlap checks.
FlxQuadTree
  _rightEdge : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _southEastTree : FlxQuadTree
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _southWestTree : FlxQuadTree
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _tailA : FlxList
Refers to the internal A and B linked lists, which are used to store objects in the leaves.
FlxQuadTree
  _tailB : FlxList
Refers to the internal A and B linked lists, which are used to store objects in the leaves.
FlxQuadTree
  _topEdge : Number
Internal, governs and assists with the formation of the tree.
FlxQuadTree
  _useBothLists : Boolean
[static] Internal, used during tree processing and overlap checks.
FlxQuadTree
Public Methods
 MethodDefined By
  
FlxQuadTree(X:Number, Y:Number, Width:Number, Height:Number, Parent:FlxQuadTree = null)
Instantiate a new Quad Tree node.
FlxQuadTree
  
add(ObjectOrGroup:FlxBasic, List:uint):void
Call this function to add an object to the root of the tree.
FlxQuadTree
 Inherited
Helper function, just copies the values from the specified rectangle.
FlxRect
 Inherited
copyFromFlash(FlashRect:Rectangle):FlxRect
Helper function, just copies the values from the specified Flash rectangle.
FlxRect
 Inherited
Helper function, just copies the values from this rectangle to the specified rectangle.
FlxRect
 Inherited
copyToFlash(FlashRect:Rectangle):Rectangle
Helper function, just copies the values from this rectangle to the specified Flash rectangle.
FlxRect
  
destroy():void
Clean up memory.
FlxQuadTree
  
execute():Boolean
FlxQuadTree's other main function.
FlxQuadTree
  
load(ObjectOrGroup1:FlxBasic, ObjectOrGroup2:FlxBasic = null, NotifyCallback:Function = null, ProcessCallback:Function = null):void
Load objects and/or groups into the quad tree, and register notify and processing callbacks.
FlxQuadTree
 Inherited
make(X:Number = 0, Y:Number = 0, Width:Number = 0, Height:Number = 0):FlxRect
Instantiate a new rectangle.
FlxRect
 Inherited
overlaps(Rect:FlxRect):Boolean
Checks to see if some FlxRect object overlaps this FlxRect object.
FlxRect
Protected Methods
 MethodDefined By
  
addObject():void
Internal function for recursively navigating and creating the tree while adding objects to the appropriate nodes.
FlxQuadTree
  
addToList():void
Internal function for recursively adding objects to leaf lists.
FlxQuadTree
  
overlapNode():Boolean
An internal function for comparing an object against the contents of a node.
FlxQuadTree
Public Constants
 ConstantDefined By
  A_LIST : uint = 0
[static] Flag for specifying that you want to add an object to the A list.
FlxQuadTree
  B_LIST : uint = 1
[static] Flag for specifying that you want to add an object to the B list.
FlxQuadTree
Property Detail
_bottomEdgeproperty
protected var _bottomEdge:Number

Internal, governs and assists with the formation of the tree.

_canSubdivideproperty 
protected var _canSubdivide:Boolean

Whether this branch of the tree can be subdivided or not.

_checkObjectHullHeightproperty 
protected static var _checkObjectHullHeight:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_checkObjectHullWidthproperty 
protected static var _checkObjectHullWidth:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_checkObjectHullXproperty 
protected static var _checkObjectHullX:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_checkObjectHullYproperty 
protected static var _checkObjectHullY:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_halfHeightproperty 
protected var _halfHeight:Number

Internal, governs and assists with the formation of the tree.

_halfWidthproperty 
protected var _halfWidth:Number

Internal, governs and assists with the formation of the tree.

_headAproperty 
protected var _headA:FlxList

Refers to the internal A and B linked lists, which are used to store objects in the leaves.

_headBproperty 
protected var _headB:FlxList

Refers to the internal A and B linked lists, which are used to store objects in the leaves.

_iteratorproperty 
protected static var _iterator:FlxList

Internal, used during tree processing and overlap checks.

_leftEdgeproperty 
protected var _leftEdge:Number

Internal, governs and assists with the formation of the tree.

_listproperty 
protected static var _list:uint

Internal, used during tree processing and overlap checks.

_midpointXproperty 
protected var _midpointX:Number

Internal, governs and assists with the formation of the tree.

_midpointYproperty 
protected var _midpointY:Number

Internal, governs and assists with the formation of the tree.

_minproperty 
protected static var _min:uint

Internal, governs and assists with the formation of the tree.

_northEastTreeproperty 
protected var _northEastTree:FlxQuadTree

Internal, governs and assists with the formation of the tree.

_northWestTreeproperty 
protected var _northWestTree:FlxQuadTree

Internal, governs and assists with the formation of the tree.

_notifyCallbackproperty 
protected static var _notifyCallback:Function

Internal, used during tree processing and overlap checks.

_objectproperty 
protected static var _object:FlxObject

Internal, used to reduce recursive method parameters during object placement and tree formation.

_objectBottomEdgeproperty 
protected static var _objectBottomEdge:Number

Internal, used to reduce recursive method parameters during object placement and tree formation.

_objectHullHeightproperty 
protected static var _objectHullHeight:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_objectHullWidthproperty 
protected static var _objectHullWidth:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_objectHullXproperty 
protected static var _objectHullX:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_objectHullYproperty 
protected static var _objectHullY:Number

Internal, helpers for comparing actual object-to-object overlap - see overlapNode().

_objectLeftEdgeproperty 
protected static var _objectLeftEdge:Number

Internal, used to reduce recursive method parameters during object placement and tree formation.

_objectRightEdgeproperty 
protected static var _objectRightEdge:Number

Internal, used to reduce recursive method parameters during object placement and tree formation.

_objectTopEdgeproperty 
protected static var _objectTopEdge:Number

Internal, used to reduce recursive method parameters during object placement and tree formation.

_processingCallbackproperty 
protected static var _processingCallback:Function

Internal, used during tree processing and overlap checks.

_rightEdgeproperty 
protected var _rightEdge:Number

Internal, governs and assists with the formation of the tree.

_southEastTreeproperty 
protected var _southEastTree:FlxQuadTree

Internal, governs and assists with the formation of the tree.

_southWestTreeproperty 
protected var _southWestTree:FlxQuadTree

Internal, governs and assists with the formation of the tree.

_tailAproperty 
protected var _tailA:FlxList

Refers to the internal A and B linked lists, which are used to store objects in the leaves.

_tailBproperty 
protected var _tailB:FlxList

Refers to the internal A and B linked lists, which are used to store objects in the leaves.

_topEdgeproperty 
protected var _topEdge:Number

Internal, governs and assists with the formation of the tree.

_useBothListsproperty 
protected static var _useBothLists:Boolean

Internal, used during tree processing and overlap checks.

divisionsproperty 
public static var divisions:uint

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

Constructor Detail
FlxQuadTree()Constructor
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.
Method Detail
add()method
public function add(ObjectOrGroup:FlxBasic, 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

ObjectOrGroup:FlxBasic — FlxObjects are just added, FlxGroups are recursed and their applicable members added accordingly.
 
List:uint — A uint flag indicating the list to which you want to add the objects. Options are A_LIST and B_LIST.

addObject()method 
protected function addObject():void

Internal function for recursively navigating and creating the tree while adding objects to the appropriate nodes.

addToList()method 
protected function addToList():void

Internal function for recursively adding objects to leaf lists.

destroy()method 
public function destroy():void

Clean up memory.

execute()method 
public function execute():Boolean

FlxQuadTree's other main function. Call this after adding objects using FlxQuadTree.load() to compare the objects that you loaded.

Returns
Boolean — Whether or not any overlaps were found.
load()method 
public function load(ObjectOrGroup1:FlxBasic, ObjectOrGroup2:FlxBasic = null, NotifyCallback:Function = null, ProcessCallback:Function = null):void

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

Parameters

ObjectOrGroup1:FlxBasic — Any object that is or extends FlxObject or FlxGroup.
 
ObjectOrGroup2:FlxBasic (default = null) — Any object that is or extends FlxObject or FlxGroup. If null, the first parameter will be checked against itself.
 
NotifyCallback:Function (default = null) — 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:Function (default = null) — 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().

overlapNode()method 
protected function overlapNode():Boolean

An internal function for comparing an object against the contents of a node.

Returns
Boolean — Whether or not any overlaps were found.
Constant Detail
A_LISTConstant
public static const A_LIST:uint = 0

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

B_LISTConstant 
public static const B_LIST:uint = 1

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