AudioManager

new AudioManager()

An audio manager. Controlls multiple sounds at once. Screen objects come with an AudioManager (Screen.audio), but you can create your own for more fine-grained control. This allows you to easily control the volume of different parts of your game independently, i.e. seperate SFX, menu, and gameplay sound sliders.

Example
import { gameify } from "./gameify/gameify.js"
const myAudioManager = new gameify.audio.AudioManager();
const mySound = new gameify.audio.Sound("my-sound.mp3");
myAudioManager.add(mySound);

Members

(readonly) sounds

Sounds this AudioManager controlls. Don't modify this - Use add() and remove() to add/remove sounds. AudioManagers are set to 20% volume by default, to protect your ears.

Methods

add(sound)

Add a sound to the AudioManager

Parameters:
NameTypeDescription
soundgameify.audio.Sound

The sound to add

getVolume() → {Number}

Get the volume of the AudioManager. Note that this volume is mixed with the volume of each sound. Use Sound.getCalculatedVolume to get the actual volume of each sound.

Returns:
Type: 
Number

setVolume(volume)

Adjust the volume of all controlled sounds

Parameters:
NameTypeDescription
volumeNumber

The volume modifier, from 0 to 1