Audio system - mganzarcik/fabulae GitHub Wiki

Audio at GameLocations

Every GameLocation can have a playlist of audio tracks defined that will play at three different events: OnEnty, OnExit and Ambient. Each track can have a chanceToPlay defined, an indicator whether or not it should be looped and whether or not it should be played more than once.

There are two types of audio tracks, Music and Sounds.

Music

Only one Music track can play at any given time. Music tracks can be interrupted by OnEntry and OnExit music tracks, but not by Ambient music tracks. If a Music track needs to be interrupted / stopped, it is faded away.

Sounds

There can be many sounds played concurrently. Sounds assigned to GameLocations will be only faded away and stopped if they are looped. Non looped sounds are stopped immediately once their GameLocation is left by all PlayerCharacters.

Audio at GameObjects

A Sound can also be assigned to GameObjects, where it can be played at different times, based on the object type (for example, sounds can be tied to animation frames for AnimatedGameObjects or they can be assigned to Projectiles). Sounds originating from GOs are only audible if any PC is within the sound radius of the GO and its volume is determined by the PCs distance from the GO.

Volume determining algorithm

The volume of any sound is determined in the following way:

  1. The configured global sound effect volume is obtained
  2. The distance of the SoundOriginator (GameLocation or GameObject) to the nearest member of the PC group is determined. If the distance is greater than the play radius of the originator, nothing is played and the algorithm ends. Otherwise the volume is linearly lowered based on this distance.
  3. The distance from the originator to the middle of the rendered area is calculated. The volume is linearly lowered based on this distance.

This algorithm is skipped for any sounds originating from PlayerCharacters. These are always played at full configured global sound effect volume.