Extends
Members
# count :number
The number of times the loop will repeat. If it's set to 0, it will repeat indefinitely.
Type:
- number
- Default Value:
- 0
# behavior :Behavior
The child behavior.
Warning: cannot be set using set(). Must be hard-coded into your derived class.
Type:
- Inherited From:
Example:
class MyDecoratorBehavior extends DecoratorBehavior {
get behavior() { return ChildBehavior; }
}
# actor :Actor
The actor that is running the behavior.
Type:
- Actor
- Inherited From:
# parent :Behavior
The parent behavior in the behavior tree.
Type:
- Inherited From:
# tickRate :number
The tick rate in milliseconds. If a behavior doesn't return an immediate result, it will run periodically at the frequency of the tick rate. If the tick rate is set to 0, the behavior won't tick and won't run do().
Type:
- number
- Inherited From:
- Default Value:
- 100
Methods
# startChild(optionsopt)
Starts the child behavior.
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
An optional options object to be passed to the child's |
- Inherited From:
# reportSuccess(child, dataopt)
Called by the child from succeed().
Name | Type | Attributes | Description |
---|---|---|---|
child |
Behavior | The child that is reporting. |
|
data |
Object |
<optional> |
Optional data from child. |
- Inherited From:
# reportFailure(child, dataopt)
Called by the child from fail().
Name | Type | Attributes | Description |
---|---|---|---|
child |
Behavior | The child that is reporting. |
|
data |
Object |
<optional> |
Optional data from child. |
- Inherited From:
# init(optionsopt)
Called when the behavior is instantiated.
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
Optional option object passed to set() |
- Inherited From:
# set(options)
Sets one or more internal properties of the behavior. The internal name of each property will be the name of the option prefaced by "_". You should define corresponding getters to access these internal properties.
class MyBehavior extends Behavior {
get growth() {return this._growth || 0.5};
}
const behavior = MyBehavior.create();
behavior.set({growth: 2});
Name | Type | Description |
---|---|---|
options |
Object |
- Inherited From:
# do(delta)
This is where the work of the behavior actually happens. If you create your own behavior
overload do
. This will be called once per tick`.
Note: do
will be called for for the first time at random interval less than the tick rate.
(This is to prevent actors that spawn simultaneously from all processing their behaviors at the save time.)
If you want something to happen instantly, put it in init instead of do
.
Name | Type | Description |
---|---|---|
delta |
number | Time in milliseconds since the last invocation of |
- Inherited From:
# destroy()
- Inherited From:
# succeed(dataopt)
Ends the behavior and reports that it has succeeded to its parent.
Name | Type | Attributes | Description |
---|---|---|---|
data |
Object |
<optional> |
An optional data object that will be passed to the parent behavior. |
- Inherited From:
# fail(dataopt)
Ends the behavior and reports that it has failed to its parent.
Name | Type | Attributes | Description |
---|---|---|---|
data |
Object |
<optional> |
An optional data object that will be passed to the parent behavior. |
- Inherited From: