arcade2d
Class

AbstractWorldComponent

world/abstract-world-component.ts:48

Extends AbstractComponent<World>

Implements WorldComponent<TDeps>

Abstract base class for components attached to a World.

The recommended way to implement the WorldComponent contract. Supplies the boilerplate every world-scoped system would otherwise write by hand:

  • The AbstractComponent.host reference, typed as World.
  • A AbstractWorldComponent.world alias (identical to host at this tier) so subclass code reads symmetrically with the AbstractWorldObjectComponent convenience.
  • A AbstractWorldComponent.game accessor that hops through the world to the parent Game — the single-step way to reach page-scoped services like the keyboard or mouse samplers.
  • No-op default implementations of the required lifecycle hooks (onAdded, onUpdate, onDestroy) so subclasses only override the ones they actually use. The optional onPreUpdate and onPostUpdate hooks remain opt-in — declare them only when needed.

Subclasses that take additional constructor arguments must define their own constructor and forward host via super(host). Subclasses that need nothing beyond the host can omit the constructor entirely and inherit the one on this base.

Example

class PauseGate extends AbstractWorldComponent {
  public onUpdate(): void {
    if (this.game.getKeyboardState().isDown('Escape')) {
      this.world.enabled = false;
    }
  }
}

Constructors

#
constructor(host: World): AbstractWorldComponent<TDeps>

Parameters

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.

readonly #
host: World

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

readonly #
game: Game

The Game the host world belongs to. Always non-null — the world's game field is a mandatory construction argument, not an option.

readonly #
world: World

The World this component is attached to — identical to AbstractComponent.host at this tier, exposed under the world name so subclass code reads the same on every tier.

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
#
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