Class

Quadtree

:

A quadtree structure

bounds

: Rect

maxObjects

: number

maxLevels

: number

level

: number

nodes

: Quadtree[]

objects

: GameObj<AreaComp>[]
get

isLeaf

(): boolean

True if this node is a leaf node.

subdivide

() => void

Splits the node, but doesn't redistribute objects

merge

() => void

Tries to merge and collapse nodes which are no longer overpopulated.

getQuadrant

(rect: Rect) =>
Parsing error with FirstLiteralToken
|
Parsing error with FirstLiteralToken
|
Parsing error with FirstLiteralToken
|
Parsing error with PrefixUnaryExpression
|
Parsing error with FirstLiteralToken

Returns the quadrant this rect fits in or -1 if it doesn't fit any quadrant

param rect- The rect to test with.

returns The index of the quadrant fitting the rect completely, or -1 if none.

getQuadrants

(rect: Rect) => number[]

Returns the quadrants this rect intersects

param rect- The rect to test with. Note that this rect is assumed to be within the node.

returns the list of quadrant indices

insert

(obj: GameObj<AreaComp>, bbox: Rect) => void

Inserts the object with the given rectangle

param obj- The object to add

param bbox- The bounding box of the object

add

(obj: GameObj<AreaComp>) => void

Add the object

param obj- The object to add

retrieve

(rect: Rect, objects: GameObj<AreaComp>[]) => void

Retrieves all objects potentially intersecting the rectangle

param rect- The rect to test with

returns A set of objects potentially intersecting the rectangle

remove

(obj: GameObj<AreaComp>, fast?: boolean) => boolean

Removes the object

param obj- The object to remove

param fast- No node collapse if true

updateObject

(root: Quadtree, obj: GameObj<AreaComp>, bbox: Rect) => void

Updates a single object Note that no testing is done here. Make sure the object needs to be actually updated.

param root- The tree root, since insertion happens from the root

param obj- The object to update

param bbox- The new bounding box

isOutside

(bbox: Rect) => boolean

True if the rectangle is completely outside this node's bounds

param bbox- The bounding box to test

isInside

(bbox: Rect) => boolean

True if the rectangle is completely outside this node's bounds

param bbox- The bounding box to test

updateNode

(orphans: [GameObj<AreaComp>, Rect][]) => void

Updates all objects in this node and the objects of its children

param orphans- The tree root, since insertion happens from the root

update

() => void

Update this tree

clear

() => void

Clears this node and collapses it

gatherPairs

(ancestorObjects: Array<GameObj<AreaComp>>, pairCb: (obj1: GameObj<AreaComp>, obj2: GameObj<AreaComp>) => void) => void

Gathers all collision pairs in this node and child nodes

param ancestorObjects- Objects in one of the node's ancestors

param pairCb- The pairs being gathered

iterPairs

(pairCb: (obj1: GameObj<AreaComp>, obj2: GameObj<AreaComp>) => void) => void
kaplay logo

Components

Miscalenous