Line 233: |
Line 233: |
| </dd> | | </dd> |
| | | |
− | ===Adding custom sounds=== | + | ===Adding custom audio=== |
| | | |
| Game audio is split up into components: | | Game audio is split up into components: |
Line 240: |
Line 240: |
| *The Soundbank stores Cues to be called, played or modified. | | *The Soundbank stores Cues to be called, played or modified. |
| | | |
− | To add your own sounds to the soundbank, you can define a new <tt>CueDefinition</tt> and add a name: | + | To add your own audio to the soundbank (whether it's a new sound or a new music track), you can define a new <tt>CueDefinition</tt> and add a name: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| CueDefinition myCueDefinition = new CueDefinition(); | | CueDefinition myCueDefinition = new CueDefinition(); |
| | | |
| // Adding the name for the cue, which will be | | // Adding the name for the cue, which will be |
− | // the name of the sound when using sound functions. | + | // the name of the audio to play when using sound functions. |
| myCueDefinition.name = "myNewSound"; | | myCueDefinition.name = "myNewSound"; |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | You can also make sure your sound will only be played one instance at a time, to prevent two of the same sound from playing over each other. | + | You can also make sure your audio will only be played with one instance at a time, to prevent two of the same audio clips from playing over each other. |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| // If this sound is played multiple times in quick succession, | | // If this sound is played multiple times in quick succession, |
Line 257: |
Line 257: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | Then, add the sound file to the cue by creating a new <tt>SoundEffect</tt>, then fetching the sound file from a new <tt>FileStream</tt> and adding it to the <tt>SoundEffect</tt>. | + | Then, add the audio file to the cue by creating a new <tt>SoundEffect</tt>, then fetching the audio file from a new <tt>FileStream</tt> and adding it to the <tt>SoundEffect</tt>. |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| // Get the audio file and add it to a SoundEffect. | | // Get the audio file and add it to a SoundEffect. |
− | SoundEffect sound_effect; | + | SoundEffect audio; |
| string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav"); | | string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav"); |
| using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)) { | | using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)) { |
− | sound_effect = SoundEffect.FromStream(stream); | + | audio = SoundEffect.FromStream(stream); |
| } | | } |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | Lastly, add the <tt>SoundEffect</tt> to the cue, and assign the cue to the soundbank to be stored. | + | Lastly, add the <tt>SoundEffect</tt> to the cue, and assign the cue to the soundbank to be stored. By setting the category index to the appropriate option, players can regulate the sound's volume with the in-game volume options (ie. sound effect or music volume sliders): |
| + | |
| + | {| class="wikitable" |
| + | |- |
| + | ! ID |
| + | ! Name |
| + | ! Use case |
| + | |- |
| + | | 1 |
| + | | <tt>Default</tt> |
| + | | This is an unused category, and should generally be avoided. |
| + | |- |
| + | | 2 |
| + | | <tt>Music</tt> |
| + | | For any music tracks, to be regulated with the in-game music volume option. |
| + | |- |
| + | | 3 |
| + | | <tt>Sound</tt> |
| + | | For any sound effects, to be regulated with the in-game sound volume option. |
| + | |- |
| + | | 4 |
| + | | <tt>Ambient</tt> |
| + | | For ambient background sounds, like wind, rain or machine whirring, that can play in the background of a scene. |
| + | |- |
| + | | 5 |
| + | | <tt>Footsteps</tt> |
| + | | For any step sounds, such as player or horse footsteps. |
| + | |} |
| + | |
| + | In this case, since the cue is meant to be played as a sound effect and not a music track, the cue's category is set to <tt>Sound</tt> by calling the getter <tt>Game1.audioEngine.GetCategoryIndex()</tt>: |
| | | |
− | If you'd like the sound to use the in-game reverb, you can set the third parameter to <tt>true</tt>:
| |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| // Setting the sound effect to the new cue. | | // Setting the sound effect to the new cue. |
− | myCueDefinition.SetSound(sound_effect, Game1.audioEngine.GetCategoryIndex("Default"), false); | + | myCueDefinition.SetSound(audio, Game1.audioEngine.GetCategoryIndex("Sound"), false); |
| | | |
| // Adding the cue to the sound bank. | | // Adding the cue to the sound bank. |
Line 278: |
Line 306: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | You should now be able to play your sound using any of the sound commands!
| + | If you just added a sound, you should now be able to play your audio using any of the sound commands! |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
| Game1.playSound("myNewSound"); | | Game1.playSound("myNewSound"); |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | ===Editing existing sounds=== | + | If you just added new music, you should now be able to add your music ID to any map. |
| + | |
| + | ===Editing existing audio=== |
| + | |
| + | To modify a cue that exists in the game, you can declare it from an existing cue as a new cue definition, and invoke <tt>CueDefinition.SetSound</tt> to apply your new audio to the cue. |
| | | |
− | To modify a sound cue that exists in the game, you can create another cue definition from an existing cue and invoke <tt>CueDefinition.SetSound</tt> to apply your new audio to the cue.
| + | As mentioned above, set your new cue's category to be the same category which the cue is included in (ie. the sound <tt>debuffHit</tt> is located in the <tt>Sound</tt> category). |
| | | |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
Line 292: |
Line 324: |
| | | |
| // Get the audio file and add it to a new SoundEffect, to replace the old one. | | // Get the audio file and add it to a new SoundEffect, to replace the old one. |
− | SoundEffect sound_effect; | + | SoundEffect audio; |
| string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav"); | | string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav"); |
| using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)) { | | using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)) { |
− | sound_effect = SoundEffect.FromStream(stream); | + | audio = SoundEffect.FromStream(stream); |
| } | | } |
| | | |
− | // Assign the new sound effect to this cue. | + | // Assign the new audio to this cue. |
− | existingCueDef.SetSound(sound_effect, audioEngine.GetCategoryIndex("Default"), false); | + | existingCueDef.SetSound(audio, audioEngine.GetCategoryIndex("Sound"), false); |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |