Flame Behaviors
Developed with
An implementation of the behavioral composition pattern for Flame.
π»
Installation flutter pub add flame_behaviors
β¨
Usage Behavior
A behavior is a component that defines how an entity behaves. It can be attached to an Entity
and handle a specific behavior for that entity.
A behavior can have it's own Component
s for adding extra functionality related to the behavior. It cannot, however, have its own Behavior
s.
// Define a custom behavior by extending `Behavior`.
class CollisionBehavior extends Behavior with CollisionCallbacks {
CollisionBehavior(this._hitbox) : super(children: [_hitbox]);
final RectangleHitbox _hitbox;
@override
Future<void> onLoad() async {...}
@override
@mustCallSuper
void onCollision(Set<Vector2> intersectionPoints, PositionComponent other) {...}
Entity
The entity is the building block of a game. It represents a visual game object that can hold multiple Behavior
s which in turn define how the entity behaves.
// Define a custom entity by extending `Entity`.
class MyEntity extends Entity {
MyEntity() : super(behaviors: [CollisionBehavior(RectangleHitbox()]);
}