Audio subscribe method

  • The subscribe function allows you to listen for changes to the isEnabled state.

  • When isEnabled changes, the provided callback function will be executed with the new state.

  • An example demonstrates how to use subscribe to control sound muting based on isEnabled.

  • The requirements for using subscribe are linked to the documentation for isEnabled.

subscribe(
  callback: (isEnabled: boolean) => void
): void

Subscribes to changes to isEnabled. callback will be called with the value of isEnabled when it changes.

Examples

engine.sound.setMute(!GameSnacks.audio.isEnabled);
GameSnacks.audio.subscribe((isEnabled) => engine.sound.setMute(!isEnabled));

Requirements

See isEnabled.