Skip to content

Class: AudioManager

Manages audio playback for the game, including music and sound effects. It interfaces with an AssetLoader to get audio data and an optional EventManager for audio-related events.

Source: core/AudioManager.js, line 12


Constructor

new AudioManager(assetLoader, eventManager)

Creates an instance of AudioManager.

Parameters:

NameTypeDefaultDescription
assetLoaderAssetLoaderAn instance of AssetLoader to load audio assets.
eventManagerEventManagernullAn optional instance of EventManager.

Source: core/AudioManager.js, line 12


Methods

destroy()

Call this when the engine is shutting down. This method typically handles cleanup, such as stopping all audio and releasing resources.

Source: core/AudioManager.js, line 317


pauseAll()

Pauses the AudioContext (suspends all audio). This is useful for when the game is paused or loses focus.

Source: core/AudioManager.js, line 228


playMusic(assetName, loop?, volume?, fadeInDuration?)

Plays background music. Stops any currently playing music.

Parameters:

NameTypeAttributesDefaultDescription
assetNamestringThe name of the pre-loaded audio asset (AudioBuffer).
loopbooleanoptionaltrueWhether the music should loop.
volumenumberoptional1.0Volume for this music track (0-1), relative to the global musicVolume.
fadeInDurationnumberoptional0Duration in seconds for a fade-in effect.

Source: core/AudioManager.js, line 127


playSoundEffect(assetName, volume?, playbackRate?, startTime?)

Plays a sound effect.

Parameters:

NameTypeAttributesDefaultDescription
assetNamestringThe name of the pre-loaded audio asset (AudioBuffer).
volumenumberoptional1.0Volume for this specific sound (0-1), relative to the global sfxVolume.
playbackRatenumberoptional1.0Speed of playback.
startTimenumberoptional0Offset in seconds to start playing from.

Returns: AudioBufferSourceNode | null The created source node, or null if the sound cannot be played (e.g., asset not found or audio context issue).

Source: core/AudioManager.js, line 90


resumeAll()

Resumes the AudioContext (resumes all audio). Needs user interaction to start/resume AudioContext if it was suspended by browser policy (e.g., after a page load before any user click).

Source: core/AudioManager.js, line 240


stopMusic(fadeOutDuration?)

Stops the currently playing background music.

Parameters:

NameTypeAttributesDefaultDescription
fadeOutDurationnumberoptional0Duration in seconds for a fade-out effect.

Source: core/AudioManager.js, line 175

Released under the MIT License (Placeholder).