FlxAudioManager
Owns the audio backend, the music singleton, and the sound-effects group.
Registered on the FlxContext service map via FLX_AUDIO_SERVICE. FlxG resolves it to expose FlxG.music, FlxG.sounds, FlxG.play(), FlxG.playMusic(), FlxG.stream(), FlxG.volume, FlxG.mute, FlxG.pauseSounds(), and FlxG.resumeSounds().
export declare class FlxAudioManager implements FlxAudioServiceConstructors
constructor(context: FlxContext, backend: FlxAudioBackend)Constructs a new instance of the FlxAudioManager class
| Parameter | Type | Description |
|---|---|---|
context | FlxContext | - |
backend | FlxAudioBackend | - |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
music | - | FlxSound | null | - |
musicGroup | readonly | FlxSoundGroup | - |
mute | - | boolean | - |
soundGroup | readonly | FlxSoundGroup | - |
sounds | readonly | FlxGroup | - |
volume | - | number | - |
Methods
destroy()
destroy(): voidFull teardown.
Returns: void
destroySounds()
destroySounds(forceDestroy: boolean): voidRemove non-survive sounds on state switch.
Parameters:
| Parameter | Type | Description |
|---|---|---|
forceDestroy | boolean | If true, destroy survive sounds too. |
Returns: void
onChange()
onChange(listener: (state: FlxAudioState) => void): () => voidSubscribe to master audio preference changes.
Parameters:
| Parameter | Type | Description |
|---|---|---|
listener | (state: FlxAudioState) => void | - |
Returns: () => void
pauseSounds()
pauseSounds(): voidPause all sounds and music.
Returns: void
play()
play(source: unknown, volume?: number, loop?: boolean, autoDestroy?: boolean, group?: FlxSoundGroup): FlxSoundPlay a sound effect.
Parameters:
| Parameter | Type | Description |
|---|---|---|
source | unknown | AudioBuffer, HTMLAudioElement, or URL string. |
volume | number | Per-instance volume (0–1). Defaults to 1. |
loop | boolean | Whether to loop. Defaults to false. |
autoDestroy | boolean | Whether to auto-destroy when done. Defaults to true. |
group | FlxSoundGroup | - |
Returns: FlxSound
playMusic()
playMusic(source: unknown, volume?: number, group?: FlxSoundGroup): voidPlay music, stopping the current track.
Parameters:
| Parameter | Type | Description |
|---|---|---|
source | unknown | AudioBuffer, HTMLAudioElement, or URL string. |
volume | number | Volume (0–1). Defaults to 1. |
group | FlxSoundGroup | - |
Returns: void
resumeSounds()
resumeSounds(): voidResume all sounds and music.
Returns: void
stream()
stream(url: string, volume?: number, loop?: boolean, autoDestroy?: boolean, group?: FlxSoundGroup): FlxSoundPlay a streaming sound from a URL.
Parameters:
| Parameter | Type | Description |
|---|---|---|
url | string | The streaming URL. |
volume | number | Per-instance volume (0–1). Defaults to 1. |
loop | boolean | Whether to loop. Defaults to false. |
autoDestroy | boolean | Whether to auto-destroy when done. Defaults to true. |
group | FlxSoundGroup | - |
Returns: FlxSound
updateSounds()
updateSounds(elapsed: number): voidCalled by FlxGame.step() to advance fades, proximity, and auto-destroy.
Parameters:
| Parameter | Type | Description |
|---|---|---|
elapsed | number | - |
Returns: void