Class QuadTree

a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.

See

game.world.broadphase

Constructors

constructor

  • new QuadTree(world, bounds, max_objects?, max_levels?, level?): QuadTree
  • Parameters

    • world: World

      the physic world this QuadTree belongs to

    • bounds: Bounds

      bounds of the node

    • Optionalmax_objects: number = 4

      max objects a node can hold before splitting into 4 subnodes

    • Optionalmax_levels: number = 4

      total max levels inside root Quadtree

    • Optionallevel: number = 0

      deepth level, required for subnodes

    Returns QuadTree

Properties

bounds

bounds: Bounds

level

level: number

max_levels

max_levels: number

max_objects

max_objects: number

nodes

nodes: any[]

objects

objects: any[]

world

world: World

Methods

clear

getIndex

hasChildren

insert

  • insert(item): void
  • Insert the given object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.

    Parameters

    • item: object

      object to be added

    Returns void

insertContainer

isPrunable

remove

  • remove(item): boolean
  • Remove the given item from the quadtree. (this function won't recalculate the impacted node)

    Parameters

    • item: object

      object to be removed

    Returns boolean

    true if the item was found and removed.

retrieve

  • retrieve(item, fn?): object[]
  • Return all objects that could collide with the given object

    Parameters

    • item: object

      object to be checked against

    • Optionalfn: object

      a sorting function for the returned array

    Returns object[]

    array with all detected objects

split

Settings

Member Visibility

On This Page

AltStyle によって変換されたページ (->オリジナル) /