API Docs for: 0.1.1
Show:

flatworld.utils.Quadtree Class

NOTE! NOT IN USE AT THE MOMENT. THIS WAS LESS EFFICIENT THAN USING SUBCONTAINERS, SO IT WILL BE USED IN THE FUTURE IF NEEDED.

This class handles the API for quadtree to search for the wanted objects on the certain coordinates. After this the map should do it's own - more precise - hit detections.

Constructor

flatworld.utils.Quadtree

(
  • options
  • max
)

Parameters:

  • options Object

    options for the QuadModule

  • max Object

    How many levels deep

Returns:

Quadtree instance

Methods

_creteQuadtreeObject

(
  • coords
  • size
  • data
)
Object private static

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object if you wish, instead of point / coordinates

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)

  • data Object

    Extra data stored for the quadtree object

Returns:

Object:

Added quadtree object

add

(
  • coords
  • size
  • data
)

Add an object to the quadtree.

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object "hit" detection

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)

  • data Object

    Objects extra custom data. This is optional.

Returns:

Quadtree instance

findObject

(
  • coords
  • size
  • data
)
Object

Find an object by hitDetection from the quadtree setting.

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object "hit" detection

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)

  • data Object

    Objects extra custom data. This is optional.

Returns:

Object:

Found object

move

(
  • coords
  • size
  • data
  • to
)
Boolean

Move an object on the quadtree

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object "hit" detection

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)

  • data Object

    Objects extra custom data. This is optional.

  • to Boolean

    Should we refresh the quadtree setting, after removal. Can take some resources to execute. So we want this to be optional.

Returns:

Boolean:

True of false

refreshAll

()

refresh the whole quadtree setting. Can spend some resources.

remove

(
  • coords
  • size
  • data
  • refresh
)

Remove an object from the quadtree.

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object "hit" detection

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)

  • data Object

    Objects extra custom data. This is optional.

  • refresh Boolean

    Should we refresh the quadtree setting, after removal. Can take some resources to execute. So we want this to be optional.

Returns:

Quadtree instance

retrieve

(
  • coords
  • size
)

Parameters:

  • coords Object

    Coordinates on the global / canvas element.

    • x Integer

      X coordinate

    • y Integer

      Y coordinate

  • size Object

    You can use bounds for the object "hit" detection

    • width Integer

      Width (in pixels)

    • height Integer

      Height (in pixels)