PropagatingCollisionBehavior<Parent extends EntityMixin> constructor

PropagatingCollisionBehavior<Parent extends EntityMixin>(
  1. ShapeHitbox _hitbox, {
  2. int? priority,
  3. ComponentKey? key,
})

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.

The parent to which this behavior is added should be a PositionComponent that uses the EntityMixin. Flame behaviors comes with the PositionedEntity which does exactly that but any kind of position component will work.

Implementation

PropagatingCollisionBehavior(
  this._hitbox, {
  super.priority,
  super.key,
}) : super(children: [_hitbox]);