arcade2d
Interface

Component

components.types.ts:65

Defines a component that can be added to a host object.

Component<THost> is the structural primitive — the lowest-level shape the engine recognises. For most game code you'll reach for one of the named specialisations instead:

Those specialisations layer on a typed resolveDependencies method and a richer dependency-aware lifecycle on top of this primitive.

Update phases

Each world tick runs three update phases in order, and every component on every host is offered each phase before any host advances to the next:

  1. onPreUpdate — sample/prepare state that downstream components will consume. Good places for input polling, per-frame buffer clears, or interpolation snapshots.
  2. onUpdate — the main per-frame work: behaviour logic, movement, simulation. This is the phase that the majority of components will implement.
  3. onPostUpdate — react to the result of everyone else's onUpdate. Canonical use case: a camera reading the player's already-moved position, or a graphics component syncing its transform from the host position one final time so it never lags by a frame.

Within a single phase, world-scoped components run before object-scoped components — see World.update for the full schedule. All three update hooks are skipped on components whose Component.enabled field is explicitly false.

onPreUpdate and onPostUpdate are optional — a component that only needs the main phase can omit them and the engine will skip them at zero cost. onUpdate, onAdded, and onDestroy are required so the engine can rely on them being callable.

Dependencies

Every lifecycle hook receives a deps argument carrying the dependencies declared by the component's optional resolveDependencies method. Components with no dependencies see an empty object and almost always omit the parameter at their hook signatures — TypeScript allows dropping trailing parameters when implementing the interface. Components that do declare dependencies should reach for WorldComponent or WorldObjectComponent so the deps parameter is properly typed everywhere it appears.

Properties

#
enabled?: boolean

Optional gate on the three update hooks (onPreUpdate, onUpdate, onPostUpdate). When explicitly false, the engine skips all three for this component during the world tick — useful for temporarily pausing behaviour (e.g. a freeze powerup) without removing the component and losing its internal state.

Absent or true means "active." The flag does not gate onAdded/onDestroy; those always fire so the host can never end up with a half-attached component.

readonly #
host: THost

The host object that this component is attached to.

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

  • deps TDeps

Returns

void
#
onDestroy(deps: TDeps): void

Lifecycle hook that is called when the host object is destroyed. Should not be called directly.

Parameters

  • deps TDeps

Returns

void
#
onPostUpdate(update: WorldUpdate, deps: TDeps): void

Optional lifecycle hook for the post-update phase. Called once per world tick, after every component's onUpdate has run. Use for work that has to observe the world after this tick's behaviour has been applied — camera follow, transform sync, late-frame audit logs.

Parameters

Returns

void
#
onPreUpdate(update: WorldUpdate, deps: TDeps): void

Optional lifecycle hook for the pre-update phase. Called once per world tick, before any component on any host has its onUpdate called. Use for state preparation work that other components' onUpdate will read.

Parameters

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

Returns

void
ESC