AbstractGameComponent
abstract-game-component.ts:50 Extends AbstractComponent<Game>
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
hostat 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 optionalonPreUpdateandonPostUpdatehooks 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
-
hostGame
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.
Accessors
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
-
_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