Class: QuadTree

Phaser. QuadTree

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/

new QuadTree(physicsManager, x, y, width, height, maxObjects, maxLevels, level)

QuadTree Constructor

Parameters:
Name Type Description
physicsManager Description

Description.

x Description

Description.

y Description

Description.

width number

The width of your game in game pixels.

height number

The height of your game in game pixels.

maxObjects number

Description.

maxLevels number

Description.

level number

Description.

Source:

Methods

clear()

/* Clear the quadtree.

Source:

getIndex(rect) → {number}

/* Determine which node the object belongs to.

Parameters:
Name Type Description
rect object

Description.

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
body object

Description.

Source:

retrieve(rect) → {array}

/* Return all objects that could collide with the given object.

Parameters:
Name Type Description
rect object

Description.

Source:
Returns:
  • Array with all detected objects.
Type
array

split()

/* Split the node into 4 subnodes

Source:
Phaser Copyright © 2012-2013 Photon Storm Ltd.
Documentation generated by JSDoc 3.2.0-dev on Thu Oct 03 2013 02:35:49 GMT+0100 (BST) using the DocStrap template.