PropagatingCollisionBehavior<Parent extends PositionedEntity> constructor

PropagatingCollisionBehavior<Parent extends PositionedEntity>(
  1. ShapeHitbox _hitbox
)

This behavior is used to handle collisions between entities and propagates the collision through to any CollisionBehaviors that are attached to the entity.

The CollisionBehaviors are filtered by the CollisionBehavior.isValid method by checking if the colliding entity is valid for the given behavior and if the colliding entity is valid the CollisionBehavior.onCollision is called.

This allows for strongly typed collision detection. Without having to add multiple collision behaviors for different types of entities or adding more logic to a single collision detection behavior.

If you have an entity that does not require any CollisionBehaviors of its own, you can just add the hitbox directly to the entity's children. Any other entity that has a CollisionBehavior for that entity attached will then be able to collide with it.

Note: This behavior can also be used for collisions between entities and non-entity components, by passing the component's type as the Collider to the CollisionBehavior.

Implementation

PropagatingCollisionBehavior(this._hitbox) : super(children: [_hitbox]);