Skip to main content

Class: SoundManager

Internal

Fetches, loads, and provides sounds to the game.

For m2c2kit library use only

Constructors

new SoundManager()

new SoundManager(game, baseUrls): SoundManager

Parameters

game: Game

baseUrls: GameBaseUrls

Returns

SoundManager

Defined in

m2c2kit/packages/core/src/SoundManager.ts:19

Accessors

audioContext

Get Signature

get audioContext(): AudioContext

Returns

AudioContext

Defined in

m2c2kit/packages/core/src/SoundManager.ts:24

Methods

decodeFetchedSounds()

decodeFetchedSounds(): Promise<void[]>

Internal

Decodes all fetched sounds from bytes to an AudioBuffer.

For m2c2kit library use only

Returns

Promise<void[]>

A promise that completes when all fetched sounds have been decoded

Remarks

This method will be called after the AudioContext has been created and if there are fetched sounds waiting to be decoded.

Defined in

m2c2kit/packages/core/src/SoundManager.ts:170


dispose()

dispose(): void

Internal

Frees up resources allocated by the SoundManager.

For m2c2kit library use only

Returns

void

Remarks

This will be done automatically by the m2c2kit library; the end-user must not call this.

Defined in

m2c2kit/packages/core/src/SoundManager.ts:235


fetchDeferredSound()

fetchDeferredSound(m2Sound): Promise<void>

Internal

Fetches a m2c2kit sound (M2Sound) that was previously initialized with lazy loading.

For m2c2kit library use only

Parameters

m2Sound: M2Sound

M2Sound to fetch

Returns

Promise<void>

A promise that completes when sounds have been fetched

Defined in

m2c2kit/packages/core/src/SoundManager.ts:139


getSound()

getSound(soundName): M2Sound

Internal

Returns a m2c2kit sound (M2Sound) that has been entered into the SoundManager.

For m2c2kit library use only

Parameters

soundName: string

sound's name as defined in the game's sound assets

Returns

M2Sound

a m2c2kit sound

Remarks

Typically, a user won't need to call this because sound initialization and processing is handled by the framework.

Defined in

m2c2kit/packages/core/src/SoundManager.ts:219


getSoundNames()

getSoundNames(): string[]

Gets names of sounds entered in the SoundManager.

Returns

string[]

array of sound names

Remarks

These are sounds that the SoundManager is aware of. The sounds may not be ready to play (may not have been fetched or decoded yet).

Defined in

m2c2kit/packages/core/src/SoundManager.ts:245


hasSoundsToDecode()

hasSoundsToDecode(): boolean

Internal

Checks if the SoundManager has sounds needing decoding.

For m2c2kit library use only

Returns

boolean

true if there are sounds that have been fetched and are waiting to be decoded (status is M2SoundStatus.Fetched)

Defined in

m2c2kit/packages/core/src/SoundManager.ts:152


initializeSounds()

initializeSounds(soundAssets): Promise<void>

Internal

Loads sound assets during the game initialization.

For m2c2kit library use only

Parameters

soundAssets: undefined | SoundAsset[]

array of SoundAsset objects

Returns

Promise<void>

Remarks

Typically, a user won't call this because the m2c2kit framework will call this automatically. At initialization, sounds can only be fetched, not decoded because the AudioContext can not yet be created (it requires a user interaction).

Defined in

m2c2kit/packages/core/src/SoundManager.ts:48


loadSounds()

loadSounds(soundAssets): Promise<void>

Loads an array of sound assets and makes them ready for the game.

Parameters

soundAssets: SoundAsset[]

an array of SoundAsset

Returns

Promise<void>

A promise that completes when all sounds have loaded

Remarks

Loading a sound consists of 1) fetching the sound file and 2) decoding the sound data. The sound is then ready to be played. Step 1 can be done at any time, but step 2 requires an AudioContext, which can only be created after a user interaction. If a play Action is attempted before the sound is ready (either it has not been fetched or decoded), the play Action will log a warning to the console and the loading process will continue in the background, and the sound will play when ready. This loadSounds() method does not have to be awaited.

Defined in

m2c2kit/packages/core/src/SoundManager.ts:70