-
Notifications
You must be signed in to change notification settings - Fork 35
Adding Audio
This page is specifically for sound effects. Adding music is significantly more complicated due to requiring interaction with the game's existing music system to change what songs are played.
Slay the Spire defines its sound effects using string keys, which are passed to the various play methods of SoundMaster to play the corresponding sound effect. CardCrawlGame.sound is the instance of SoundMaster these methods are called on.
Custom sound effects can be added using BaseMod's AddAudioSubscriber, which can then be played the same way, using the string keys of sounds you add. BasicMod is set up to load audio files based on the variables defined in the Sounds class.
The Sounds class contains two examples already.
public static String TEST_SOUND = audioPath("test.wav"); //Load audio using a given path
public static String ding; //Load audio from audioPath based on the field nameBasicMod will load a sound effect from the audio folder in resources based on the variables defined in the Sounds class.
If a variable is given a value, that will be used as the filepath to load from. audioPath will return a path leading to a file in the audio folder. Alternatively if a variable is not given a value, the variable's name will be used instead. So ding loads the equivalent of audioPath("ding");, checking for the common audio extensions of .ogg, .wav, and .mp3. You can find this code in loadAudio in the main mod file.
To play these sound effects, you can then use these defined variables directly. So to play ding, you could call CardCrawlGame.sound.play(Sounds.ding);. There are other play methods such as playA, playV, and playAV that allow you to adjust the pitch and volume of the sound played.