Packageorg.flixel
Classpublic class FlxQuadTree
InheritanceFlxQuadTree Inheritance FlxRect Inheritance FlxPoint 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
 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
FlxPoint
 Inheritedy : Number
FlxPoint
Protected Properties
 PropertyDefined By
  _b : Number
FlxQuadTree
  _canSubdivide : Boolean
Whether this branch of the tree can be subdivided or not.
FlxQuadTree
  _headA : FlxList
These variables refer to the internal A and B linked lists, which are used to store objects in the leaves.
FlxQuadTree
  _headB : FlxList
FlxQuadTree
  _hh : Number
FlxQuadTree
  _hw : Number
FlxQuadTree
  _l : Number
FlxQuadTree
  _min : uint
[static] These variables refer to the potential child quadrants for this node.
FlxQuadTree
  _mx : Number
FlxQuadTree
  _my : Number
FlxQuadTree
  _ne : FlxQuadTree
FlxQuadTree
  _nw : FlxQuadTree
FlxQuadTree
  _o : FlxObject
[static] These objects are used to reduce recursive parameters internally.
FlxQuadTree
  _oa : uint
[static]
FlxQuadTree
  _ob : Number
[static]
FlxQuadTree
  _oc : Function
[static]
FlxQuadTree
  _ol : Number
[static]
FlxQuadTree
  _or : Number
[static]
FlxQuadTree
  _ot : Number
[static]
FlxQuadTree
  _r : Number
FlxQuadTree
  _se : FlxQuadTree
FlxQuadTree
  _sw : FlxQuadTree
FlxQuadTree
  _t : Number
FlxQuadTree
  _tailA : FlxList
FlxQuadTree
  _tailB : FlxList
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(Object:FlxObject, List:uint):void
Call this function to add an object to the root of the tree.
FlxQuadTree
  
overlap(BothLists:Boolean = true, Callback:Function = null):Boolean
FlxQuadTree's other main function.
FlxQuadTree
 Inherited
toString():String
Convert object to readable string name.
FlxPoint
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(Iterator:FlxList = null):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
_bproperty
protected var _b:Number

_canSubdivideproperty 
protected var _canSubdivide:Boolean

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

_headAproperty 
protected var _headA:FlxList

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

_headBproperty 
protected var _headB:FlxList

_hhproperty 
protected var _hh:Number

_hwproperty 
protected var _hw:Number

_lproperty 
protected var _l:Number

_minproperty 
protected static var _min:uint

These variables refer to the potential child quadrants for this node.

_mxproperty 
protected var _mx:Number

_myproperty 
protected var _my:Number

_neproperty 
protected var _ne:FlxQuadTree

_nwproperty 
protected var _nw:FlxQuadTree

_oproperty 
protected static var _o:FlxObject

These objects are used to reduce recursive parameters internally.

_oaproperty 
protected static var _oa:uint

_obproperty 
protected static var _ob:Number

_ocproperty 
protected static var _oc:Function

_olproperty 
protected static var _ol:Number

_orproperty 
protected static var _or:Number

_otproperty 
protected static var _ot:Number

_rproperty 
protected var _r:Number

_seproperty 
protected var _se:FlxQuadTree

_swproperty 
protected var _sw:FlxQuadTree

_tproperty 
protected var _t:Number

_tailAproperty 
protected var _tailA:FlxList

_tailBproperty 
protected var _tailB:FlxList

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

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.

overlap()method 
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.
overlapNode()method 
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.
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.