new QuadTree(x, y, width, height, maxObjects, maxLevels, level)
QuadTree Constructor
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
x |
number | The top left coordinate of the quadtree. |
||
y |
number | The top left coordinate of the quadtree. |
||
width |
number | The width of the quadtree in pixels. |
||
height |
number | The height of the quadtree in pixels. |
||
maxObjects |
number |
<optional> |
10 | The maximum number of objects per node. |
maxLevels |
number |
<optional> |
4 | The maximum number of levels to iterate to. |
level |
number |
<optional> |
0 | Which level is this? |
- Source:
Members
-
bounds
-
- Source:
Properties:
Name Type Description boundsobject Object that contains the quadtree bounds.
-
level
-
- Source:
Properties:
Name Type Description levelnumber The current level.
-
maxLevels
-
- Default Value:
- 4
- Source:
Properties:
Name Type Description maxLevelsnumber The maximum number of levels to break down to.
-
maxObjects
-
- Default Value:
- 10
- Source:
Properties:
Name Type Description maxObjectsnumber The maximum number of objects per node.
-
nodes
-
- Source:
Properties:
Name Type Description nodesarray Array of associated child nodes.
-
objects
-
- Source:
Properties:
Name Type Description objectsarray Array of quadtree children.
Methods
-
clear()
-
Clear the quadtree.
- Source:
-
getIndex(rect) → {number}
-
Determine which node the object belongs to.
Parameters:
Name Type Description rectPhaser.Rectangle | object The bounds in which to check.
- Source:
Returns:
index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
- Type
- number
-
insert(body)
-
Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.
Parameters:
Name Type Description bodyPhaser.Physics.Arcade.Body | object The Body object to insert into the quadtree. Can be any object so long as it exposes x, y, right and bottom properties.
- Source:
-
populate(group)
-
Populates this quadtree with the children of the given Group. In order to be added the child must exist and have a body property.
Parameters:
Name Type Description groupPhaser.Group The Group to add to the quadtree.
- Source:
-
populateHandler(sprite)
-
Handler for the populate method.
Parameters:
Name Type Description spritePhaser.Sprite | object The Sprite to check.
- Source:
-
reset(x, y, width, height, maxObjects, maxLevels, level)
-
Resets the QuadTree.
Parameters:
Name Type Argument Default Description xnumber The top left coordinate of the quadtree.
ynumber The top left coordinate of the quadtree.
widthnumber The width of the quadtree in pixels.
heightnumber The height of the quadtree in pixels.
maxObjectsnumber <optional>
10 The maximum number of objects per node.
maxLevelsnumber <optional>
4 The maximum number of levels to iterate to.
levelnumber <optional>
0 Which level is this?
- Source:
-
retrieve(source) → {array}
-
Return all objects that could collide with the given Sprite or Rectangle.
Parameters:
Name Type Description sourcePhaser.Sprite | Phaser.Rectangle The source object to check the QuadTree against. Either a Sprite or Rectangle.
- Source:
Returns:
- Array with all detected objects.
- Type
- array
-
split()
-
Split the node into 4 subnodes
- Source: