initializeCollisionDetection method

void initializeCollisionDetection({
  1. required Rect mapDimensions,
  2. double? minimumDistance,
  3. int maxObjects = 25,
  4. int maxLevels = 10,
})

Initialize the QuadTree.

  • mapDimensions describes the collision area coordinates and size. Should match to game map's position and size.
  • maxObjects (optional) - maximum amount of objects in one quadrant.
  • maxLevels (optional) - maximum number of nested quadrants.
  • minimumDistance (optional) - specify minimum distance between objects to consider them as possibly colliding. You can also implement the minimumDistanceCheck if you need some custom behavior.

The onComponentTypeCheck checks if objects of different types should collide. The result of the calculation is cached so you should not check any dynamical parameters here, the function is intended to be used as pure type checker. It should usually not be overridden, see CollisionCallbacks.onComponentTypeCheck instead

Implementation

void initializeCollisionDetection({
  required Rect mapDimensions,
  double? minimumDistance,
  int maxObjects = 25,
  int maxLevels = 10,
}) {
  _collisionDetection = QuadTreeCollisionDetection(
    mapDimensions: mapDimensions,
    maxDepth: maxLevels,
    maxObjects: maxObjects,
    onComponentTypeCheck: onComponentTypeCheck,
    minimumDistanceCheck: minimumDistanceCheck,
  );
  this.minimumDistance = minimumDistance;
}