-
Notifications
You must be signed in to change notification settings - Fork 16
Core 05 Creating And Using Trees
Renato Pereira edited this page Oct 27, 2014
·
1 revision
You can create a tree manually, defining all nodes in the graph in code. For example:
var tree = new b3.BehaviorTree();
tree.root = new b3.Sequence({children: [
new b3.Priority({children: [
new MyCustomNode(),
new MyCustomNode()
]}),
]});
You also can create a tree from JSON files, usually created in the editor:
var tree = new b3.BehaviorTree();
tree.load({
'title' : 'Behavior Tree title'
'description' : 'My description'
'root' : 'node-id-1'
'nodes' : {
'node-id-1' : {
'name' : 'Priority',
'title' : 'Root Node',
'description' : 'Description',
'children' : ['node-id-2', 'node-id-3'],
},
...
}
})
Usually, you want to define a target object to be controlled by the behavior tree. This target object can be anything: a function, an object, a string, a DOM element; this depends on your application.
You will also need to create a blackboard object (the memory), usually one for each target.
With the target and the blackboard objects. You just need to "tick" the tree and the magic will happen:
var target = new Image(); // The target will be an Image element
var blackboard = new b3.Blackboard();
tree.tick(target, blackboard);
Pages:
Core Guide:
- [01. Introduction](Core 01 Introduction)
- [02. Downloading and Setting Up](Core 02 Downloading and Setting Up)
- [03. General Guidelines](Core 03 General Guidelines)
- [04. Creating Custom Nodes](Core 04 Creating Custom Nodes)
- [05. Creating and Using Trees](Core 05 Creating and Using Trees)
Editor Guide:
- [01. Interface](Editor 01 Interface)
- [02. Adding and Connecting](Editor 02 Adding and Connecting)
- [03. Selecting and Moving](Editor 03 Selecting and Moving)
- [04. Node Properties](Editor 04 Node Properties)
- [05. Custom Nodes](Editor 05 Custom Nodes)
- [06. Importing and Exporting using JSON](Editor 06 Importing and Exporting using JSON)