A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts.

However I've tweaked it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result.

Original version at https://github.com/timohausmann/quadtree-js/

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 code: math/QuadTree.js (Line 23)

- Source code: math/QuadTree.js (Line 45)
- Source code: math/QuadTree.js (Line 40)
- Default Value
- 4

- Source code: math/QuadTree.js (Line 35)
- Default Value
- 10

- Source code: math/QuadTree.js (Line 29)
- Source code: math/QuadTree.js (Line 55)
- Source code: math/QuadTree.js (Line 50)

Object that contains the quadtree bounds.

The current level.

The maximum number of levels to break down to.

The maximum number of objects per node.

Array of associated child nodes.

Array of quadtree children.

- Source code: math/QuadTree.js (Line 295)
- Source code: math/QuadTree.js (Line 203)
- Source code: math/QuadTree.js (Line 151)
- Source code: math/QuadTree.js (Line 103)
- Source code: math/QuadTree.js (Line 115)
- Source code: math/QuadTree.js (Line 69)
- Array with all detected objects.
- Source code: math/QuadTree.js (Line 247)
- Source code: math/QuadTree.js (Line 130)

Clear the quadtree.

Determine which node the object belongs to.

Name | Type | Description |
---|---|---|

`rect` | Phaser.Rectangle | object | The bounds in which to check. |

number -

index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.

Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.

Name | Type | Description |
---|---|---|

`body` | Phaser.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. |

Populates this quadtree with the children of the given Group. In order to be added the child must exist and have a body property.

Name | Type | Description |
---|---|---|

`group` | Phaser.Group | The Group to add to the quadtree. |

Handler for the populate method.

Name | Type | Description |
---|---|---|

`sprite` | Phaser.Sprite | object | The Sprite to check. |

Resets the QuadTree.

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? |

Return all objects that could collide with the given Sprite or Rectangle.

Name | Type | Description |
---|---|---|

`source` | Phaser.Sprite | Phaser.Rectangle | The source object to check the QuadTree against. Either a Sprite or Rectangle. |

array -

Split the node into 4 subnodes

© 2016 Richard Davey, Photon Storm Ltd.

Licensed under the MIT License.

http://phaser.io/docs/2.6.2/Phaser.QuadTree.html