AbstractWorldObjectComponent
world/abstract-world-object-component.ts:52 Extends AbstractComponent<WorldObject>
Implements WorldObjectComponent<TDeps>
Abstract base class for components attached to a WorldObject.
The recommended way to implement the WorldObjectComponent contract. Supplies the boilerplate every per-object system would otherwise write by hand:
- The AbstractComponent.host reference, typed as WorldObject.
- A AbstractWorldObjectComponent.world accessor that hops
through the host to the parent World — the short-hand for
the very common
this.host.world.findOneByTag(...)/this.host.world.camera.shake(...)patterns. - A AbstractWorldObjectComponent.game accessor that hops one further through the world to the Game — the single-step way to reach page-scoped services like the keyboard or mouse samplers from inside per-object behaviour code.
- No-op default implementations of the required lifecycle hooks
(
onAdded,onUpdate,onDestroy) so subclasses only override the ones they actually use.
Subclasses that take additional constructor arguments must define
their own constructor and forward host via super(host).
Example
class WASDController extends AbstractWorldObjectComponent {
public onUpdate(update: WorldUpdate): void {
const keys = this.game.getKeyboardState();
const speed = 0.2 * update.deltaMilliseconds;
if (keys.isDown('KeyW')) this.host.position.y -= speed;
if (keys.isDown('KeyS')) this.host.position.y += speed;
if (keys.isDown('KeyA')) this.host.position.x -= speed;
if (keys.isDown('KeyD')) this.host.position.x += speed;
}
}Constructors
constructor(host: WorldObject): AbstractWorldObjectComponent<TDeps> Parameters
-
hostWorldObject
Properties
enabled: boolean Per-component gate on the three update hooks (onPreUpdate,
onUpdate, onPostUpdate). When explicitly false, the engine skips
all three for this component during the host's tick — useful for
temporarily pausing behaviour (e.g. a freeze powerup) without removing
the component and losing its internal state.
Does not gate onAdded or onDestroy; those always fire so a host can
never end up with a half-attached component.
host: WorldObject The host this component is attached to. Stored read-only;
subclasses access it as this.host directly, or through the
tier-appropriate aliases (this.world, this.game) on the per-tier
abstract bases.
Accessors
Methods
onAdded(_deps: TDeps): void Lifecycle hook that is called when the component is added to the host object. Should not be called directly.
Parameters
-
_depsTDeps
Returns
void onDestroy(_deps: TDeps): void Lifecycle hook that is called when the host object is destroyed. Should not be called directly.
Parameters
-
_depsTDeps
Returns
void onUpdate(_update: WorldUpdate, _deps: TDeps): void Lifecycle hook for the main update phase. Called once per world
tick, after every component's onPreUpdate and before any
onPostUpdate.
Parameters
-
_updateWorldUpdate -
_depsTDeps
Returns
void