mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-28 23:46:52 +08:00
The status badge paths were updated and the query params `?branch=main` don't work with the old schema. https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/monitoring-workflows/adding-a-workflow-status-badge
2.6 KiB
2.6 KiB
This is a bridge package that integrates the behavior_tree dart package with Flame engine.
Features
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.
Getting started
Add this package to your Flutter project using:
flutter pub add flame_behavior_tree
Usage
-
Add the
HasBehaviorTreemixin 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
treeRootof theHasBehaviorTree.
class MyComponent extends PositionComponent with HasBehaviorTree {
Future<void> onLoad() async {
treeRoot = Selector(
children: [
Sequence(children: [task1, condition, task2]),
Sequence(...),
]
);
super.onLoad();
}
}
- Increase the
tickIntervalto make the tree tick less frequently.
class MyComponent extends PositionComponent with HasBehaviorTree {
Future<void> onLoad() async {
treeRoot = Selector(...);
tickInterval = 4;
super.onLoad();
}
}
Additional information
When working with behavior trees, keep in mind that
- nodes of a behavior tree do not necessarily update on every frame.
- avoid storing data in nodes as much as possible because it can go out of sync with rest of the game as nodes are not ticked on every frame.