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

@:value(0)staticinlineread onlyA_LIST:Int = 0

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

@:value(1)staticinlineread onlyB_LIST:Int = 1

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

@:value(0)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.

staticdivisions:Int

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

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

@:access(flixel.group.FlxTypedGroup.resolveGroup)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.

destroy():Void

Clean up memory.

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

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

Inherited Variables

Defined by FlxRect

bottom:Float

The y coordinate of the bottom of the rectangle.

read onlyisEmpty:Bool

Whether width or height of this rectangle is equal to zero or not.

left:Float

The x coordinate of the left side of the rectangle.

right:Float

The x coordinate of the right side of the rectangle.

top:Float

The y coordinate of the top of the rectangle.

Inherited Methods

Defined by FlxRect

inlineceil():FlxRect

Rounds x, y, width and height using Math.ceil()

inlinecontainsPoint(Point:FlxPoint):Bool

Returns true if this FlxRect contains the FlxPoint

Parameters:

Point

The FlxPoint to check

Returns:

True if the FlxPoint is within this FlxRect, otherwise false

inlinecopyFrom(Rect:FlxRect):FlxRect

Helper function, just copies the values from the specified rectangle.

Parameters:

Rect

Any FlxRect.

Returns:

A reference to itself.

inlinecopyFromFlash(FlashRect:Rectangle):FlxRect

Helper function, just copies the values from the specified Flash rectangle.

Parameters:

FlashRect

Any Rectangle.

Returns:

A reference to itself.

inlinecopyTo(Rect:FlxRect):FlxRect

Helper function, just copies the values from this rectangle to the specified rectangle.

Parameters:

Point

Any FlxRect.

Returns:

A reference to the altered rectangle parameter.

inlinecopyToFlash(?FlashRect:Null<Rectangle>):Rectangle

Helper function, just copies the values from this rectangle to the specified Flash rectangle.

Parameters:

Point

Any Rectangle.

Returns:

A reference to the altered rectangle parameter.

inlineequals(rect:FlxRect):Bool

Checks if this rectangle's properties are equal to properties of provided rect.

Parameters:

rect

Rectangle to check equality to.

Returns:

Whether both rectangles are equal.

inlinefloor():FlxRect

Rounds x, y, width and height using Math.floor()

inlinefromTwoPoints(Point1:FlxPoint, Point2:FlxPoint):FlxRect

Calculation of bounding box for two points

Parameters:

point1

first point to calculate bounding box

point2

second point to calculate bounding box

Returns:

this rectangle filled with the position and size of bounding box for two specified points

getRotatedBounds(degrees:Float, ?origin:FlxPoint, ?newRect:FlxRect):FlxRect

Calculates the globally aligned bounding box of a FlxRect with the given angle and origin.

Parameters:

degrees

The rotation, in degrees of the rect.

origin

The relative pivot point, or the point that the rectangle rotates around. if null , the top-left (or 0,0) is used.

newRect

Optional output FlxRect, if null, a new one is created. Note: If you like, you can pass in the input rect to manipulate it. ex: rect.calcRotatedBounds(angle, null, rect)

Returns:

A globally aligned FlxRect that fully contains the input rectangle.

Available since

4.11.0

.

intersection(rect:FlxRect, ?result:FlxRect):FlxRect

Returns the area of intersection with specified rectangle. If the rectangles do not intersect, this method returns an empty rectangle.

Parameters:

rect

Rectangle to check intersection against.

Returns:

The area of intersection of two rectangles.

inlineoffset(dx:Float, dy:Float):FlxRect

inlineoverlaps(Rect:FlxRect):Bool

Checks to see if some FlxRect object overlaps this FlxRect object.

Parameters:

Rect

The rectangle being tested.

Returns:

Whether or not the two rectangles overlap.

inlineput():Void

Add this FlxRect to the recycling pool.

inlineputWeak():Void

Add this FlxRect to the recycling pool if it's a weak reference (allocated via weak()).

inlineround():FlxRect

Rounds x, y, width and height using Math.round()

@:value({ Height : 0, Width : 0, Y : 0, X : 0 })inlineset(X:Float = 0, Y:Float = 0, Width:Float = 0, Height:Float = 0):FlxRect

Fill this rectangle with the data provided.

Parameters:

X

The X-coordinate of the point in space.

Y

The Y-coordinate of the point in space.

Width

Desired width of the rectangle.

Height

Desired height of the rectangle.

Returns:

A reference to itself.

inlinesetPosition(x:Float, y:Float):FlxRect

Shortcut for setting both x and y.

inlinesetSize(Width:Float, Height:Float):FlxRect

Shortcut for setting both width and Height.

Parameters:

Width

The new sprite width.

Height

The new sprite height.

inlinetoString():String

Convert object to readable string name. Useful for debugging, save games, etc.

inlineunion(Rect:FlxRect):FlxRect

Add another rectangle to this one by filling in the horizontal and vertical space between the two rectangles.

Parameters:

Rect

The second FlxRect to add to this one

Returns:

The changed FlxRect

inlineunionWithPoint(Point:FlxPoint):FlxRect

Add another point to this rectangle one by filling in the horizontal and vertical space between the point and this rectangle.

Parameters:

Point

point to add to this one

Returns:

The changed FlxRect