Audio Basics¶
ClanGen's audio is split into three classes: Music, Ambiance, Sound. These are jointly controlled by the AudioManager, which should be accessed in the code via game.audio.
Using game.audio you can start, check, mute, and unmute the audio as a whole. More fine control can be attained by accessing the individual classes via game.audio (for example, game.audio.music to control the music.)
Sound¶
game.audio.sound handles the sound effects.
Adding New Sounds¶
New sound effects can be added to the resources/audio/sounds folder. To link the sound to a specific trigger it must be added to resources/audio/sounds.json dictionary. The keys of this dictionary are the trigger name, while their value is a list of possible sounds for that trigger. When the trigger occurs, a random sound will be chosen from the list.
Linking Sounds to Buttons¶
UIImageButtons can be given a sound_id parameter, this is how we link triggers to buttons. By default, all buttons use the button_press sound. Hover sounds cannot be changed at this time.
Of course, sounds can also be triggered by the code at any time using the play function. We don't currently utilize this, but it could be used creatively in the future.
Ambiance¶
game.audio.ambiance handles the ambient sounds.
We currently utilize a layered approach to ambiance. We have a base track, camp overlay, and season overlay. The base will play constantly, shuffling through its possible tracks. The camp and season overlays will play on a randomised timer, adding some necessary variety.
Note
If modifying the ambiance code, it's important to note that it utilizes the pygame.mixer.music class for its base track and sound channels for the overlays.
Adding New Ambiance¶
New ambiance is added to its matching folder in resources/audio/ambiance. Separate folders are provided for each biome and for seasonal ambiance (which isn't biome specific).
The resources/audio/ambiance.json is used to create our track lists.
- Seasonal tracks should be added to their respective seasonal lists. These are "overlays", meaning short tracks that play intermittently.
- Each biome has an individual dictionary containing a
"base"list. This is the "long" ambiance that plays continuously in the background. If multiple tracks are added to thebaselist, then they will be shuffled and looped through continuously. - If a camp has specific ambiances, then it should be given in this dictionary with the key as its name (with spaces replaced by
_) and the values a list of the ambiances. These are "overlays", meaning short tracks that play intermittently.
Music¶
game.audio.music handles the music.
When not on the main menu, ClanGen plays music at random intervals.
Note
Our music system utilizes sound channels just like the sound effect system. This means that each track is loaded into memory. Care should be taken when modifying the music code so that tracks are always being removed from memory once done playing to avoid excessive memory use.
Adding New Music¶
New music is added to the resources/audio/music folder. When adding new tracks, make sure to name the file with _ instead of spaces.
resources/audio/music.json holds the playlist information.
menu_playlistwill only play on the main menu (this includes game settings, saves, and making a new Clan).- We currently have a general playlist along with some seasonal playlists.
- New playlists can be added for missing seasons and biomes without additional coding, simply add a new dictionary entry with the key as
{season/biome}_playlistin all lowercase.