miaoda-game-behavior-phaser
v0.3.0
Published
Phaser Game Object behavior-tree host for miaoda-game-behavior-core.
Readme
miaoda-game-behavior-phaser
Use this Phaser 4 adapter to run miaoda-game-behavior-core trees on Game Objects. It converts Scene update milliseconds to core seconds and exposes injectable target, obstacle, and optional route queries.
Install
pnpm add miaoda-game-behavior-phaser miaoda-game-behavior-corePhaser >=4 <5 is required.
Minimal controller
const controller = scene.behaviors.create(
enemy,
`root { selector {
sequence { condition [CanSeeTarget] action [MoveToTarget] }
action [Patrol]
} }`,
{ speed: 80, sightRange: 400 },
{
target: () => ({ x: player.x, y: player.y }),
obstacles: () => visionObstacles,
},
{ Patrol: (agent) => patrol(agent) },
);Register BehaviorPlugin as a Scene Plugin to use scene.behaviors.create(), or construct new BehaviorController(scene.events, ...) directly. The adapter reads object.x, object.y, and object.angle and writes movement through setPosition. Scene updates are converted from milliseconds to seconds before BehaviorRunner.step.
Use setTicking(false) to pause and reset() to restart the tree. destroy() and Scene shutdown are terminal; later ticking/reset calls and already-captured Scene update callbacks are inert. Return the same obstacle geometry used for vision rendering. Add findPath to the hooks when MoveToTargetAvoiding should route around terrain. Add applyPosition(next) when collision, Arcade/Matter physics, or a game model must remain the authoritative writer; otherwise the adapter calls object.setPosition directly.
The final optional create/constructor argument is BehaviorRunnerOptions; use it to inject deterministic RNG, bounded diagnostics, or a pathReplanning cache policy. Read snapshots and traces from controller.runner. The adapter only forwards these options to core. phaser-doom is the reference consumer: its behavior tree chooses attack versus cached A* pursuit while its game core still validates every requested enemy position against walls.
Public API
BehaviorController, BehaviorPlugin, BehaviorHooks, and core behavior types are exported. The adapter owns Scene lifecycle only; custom actions, combat effects, and entity destruction remain game-owned.
