defineBehavior
此内容尚不支持你的语言。
defineBehavior<
S>(name,def):ComponentDef<S>
Defined in: behavior.ts:111
Define a per-entity behavior. Returns the backing ComponentDef (so you can spawn/insert it from code), and registers the lifecycle system as a side effect.
Type Parameters
Section titled “Type Parameters”S extends object
Parameters
Section titled “Parameters”string
BehaviorDef<S>
Returns
Section titled “Returns”ComponentDef<S>
Example
Section titled “Example”export const Patrol = defineBehavior('Patrol', { state: { speed: 60 }, update(ctx, dt) { const t = ctx.get(Transform); // a copy — Transform is C++-backed t.position.x += ctx.self.speed * dt; ctx.set(Transform, t); // …so hand it back },});