BehaviorComponent
BehaviorComponent
ECS wrapper around a Behavior tree. Allows complex scripting behavior, including parallelization. Requires BehaviorSystem to be registered on EntityManager.
Kind: global class
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025
- BehaviorComponent
- new exports.BehaviorComponent()
- instance
- .clock :
ClockChannelType|number - .flags :
number - .behavior ⇒
Behavior|null - .behavior
- .setFlag(flag) ⇒
void - .clearFlag(flag) ⇒
void - .writeFlag(flag, value)
- .getFlag(flag) ⇒
boolean
- .clock :
- static
.fromOne.looping_function- .serializable :
boolean - .typeName :
string - .loop(action, [thisArg]) ⇒
BehaviorComponent - .from(b) ⇒
BehaviorComponent
new exports.BehaviorComponent()
Example
new Entity()
.add(BehaviorComponent.from(
SequenceBehavior.from([
DelayBehavior.from(10),
DieBehavior.create(),
])
))
.build(ecd); // entity will self-destruct after 10 seconds
behaviorComponent.clock : ClockChannelType | number
What clock should be used for ticking associated behavior. Some behaviors need to run at the world's simulated time, while others will need to be executed in real-world time.
Kind: instance property of BehaviorComponent
behaviorComponent.flags : number
Kind: instance property of BehaviorComponent
behaviorComponent.behavior ⇒ Behavior | null
Kind: instance property of BehaviorComponent
behaviorComponent.behavior
Note that swapping behaviors during simulation may have unintended consequences
Kind: instance property of BehaviorComponent
| Param | Type |
|---|---|
| v | Behavior |
behaviorComponent.setFlag(flag) ⇒ void
Kind: instance method of BehaviorComponent
| Param | Type |
|---|---|
| flag | number | BehaviorComponentFlag |
behaviorComponent.clearFlag(flag) ⇒ void
Kind: instance method of BehaviorComponent
| Param | Type |
|---|---|
| flag | number | BehaviorComponentFlag |
behaviorComponent.writeFlag(flag, value)
Kind: instance method of BehaviorComponent
| Param | Type |
|---|---|
| flag | number | BehaviorComponentFlag |
| value | boolean |
behaviorComponent.getFlag(flag) ⇒ boolean
Kind: instance method of BehaviorComponent
| Param | Type |
|---|---|
| flag | number | BehaviorComponentFlag |
BehaviorComponent.fromOne
use from instead
Kind: static property of BehaviorComponent
BehaviorComponent.looping_function
use loop instead
Kind: static property of BehaviorComponent
BehaviorComponent.serializable : boolean
Kind: static property of BehaviorComponent
Read only: true
BehaviorComponent.typeName : string
Kind: static property of BehaviorComponent
Read only: true
BehaviorComponent.loop(action, [thisArg]) ⇒ BehaviorComponent
Executes input function every update cycle. Will run forever, or until function throws.
Kind: static method of BehaviorComponent
| Param | Type | Description |
|---|---|---|
| action | function | function to loop over |
| [thisArg] | * |
BehaviorComponent.from(b) ⇒ BehaviorComponent
Kind: static method of BehaviorComponent
| Param | Type |
|---|---|
| b | Behavior |