arcade2d
Class

AbstractGameComponent

abstract-game-component.ts:50

Extends AbstractComponent<Game>

Implements Component<Game, TDeps>

Abstract base class for components attached to a Game.

Use this whenever you're writing a game-tier system — page-global input samplers, asset registries, audio mixers, anything that conceptually lives outside a World. The base supplies:

  • The AbstractComponent.host reference, typed as Game.
  • A AbstractGameComponent.game alias (identical to host at this tier) so callers can use the same name they would on any other abstract base.
  • No-op default implementations of the three required lifecycle hooks (onAdded, onUpdate, onDestroy) so subclasses override only the ones they care about. The optional onPreUpdate and onPostUpdate hooks remain opt-in — declare them only when you need them.

The class satisfies the structural Component interface so instances slot into any of the host's addComponent / addComponents methods exactly like a hand-written component literal.

A note on the onUpdate signature

To match the structural Component interface, onUpdate accepts a WorldUpdate as its first argument — but the Game tier's runtime passes undefined here. The argument is currently vestigial at this tier; ignore it in subclass overrides. A dedicated GameUpdate payload is planned for a future iteration.

Example

class FrameCounter extends AbstractGameComponent {
  public frames = 0;

  public onUpdate(): void {
    this.frames += 1;
  }
}

Constructors

#
constructor(host: Game): AbstractGameComponent<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: Game

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 this component is attached to — identical to AbstractComponent.host at this tier, exposed under the game 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