packages/flame_behavior_tree/README.md
This package provides a HasBehaviorTree mixin for Flame Components. It can be added to any
Component and it takes care of ticking the behavior tree along with the component's update.
Add this package to your Flutter project using:
flutter pub add flame_behavior_tree
Add the HasBehaviorTree mixin to the component that wants to follow a certain AI behavior.
class MyComponent extends Position with HasBehaviorTree {
}
Set-up a behavior tree and set its root as the treeRoot of the HasBehaviorTree.
class MyComponent extends PositionComponent with HasBehaviorTree {
Future<void> onLoad() async {
treeRoot = Selector(
children: [
Sequence(children: [task1, condition, task2]),
Sequence(...),
]
);
super.onLoad();
}
}
tickInterval to make the tree tick less frequently.class MyComponent extends PositionComponent with HasBehaviorTree {
Future<void> onLoad() async {
treeRoot = Selector(...);
tickInterval = 4;
super.onLoad();
}
}
When working with behavior trees, keep in mind that