Changes

185 bytes added ,  01:18, 22 October 2021
Added code corrections
Line 247: Line 247:  
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
CueDefinition cue_definition = new CueDefinition();
 
CueDefinition cue_definition = new CueDefinition();
 +
 +
// Adding the name for the cue, which will be
 +
// the name of the sound when using sound functions.
 
cue_definition.name = "myNewSound";
 
cue_definition.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 sound will only be played one instance at a time, to prevent two of the same sound 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 260: Line 263:  
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 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>.
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
// Make a SoundEffect object, and fetch the sound file to then add.
+
// Get the audio file and add it to a SoundEffect.
 
SoundEffect sound_effect;
 
SoundEffect sound_effect;
using (var stream = new System.IO.FileStream("mySound.wav", System.IO.FileMode.Open))
+
string filePathCombined = Path.Combine(this.Helper.DirectoryPath, "mySound.wav");
{
+
using (var stream = new System.IO.FileStream(filePathCombined, System.IO.FileMode.Open)) {
 
     sound_effect = SoundEffect.FromStream(stream);
 
     sound_effect = SoundEffect.FromStream(stream);
 
}
 
}
Line 272: Line 275:  
If you'd like the sound to use the in-game reverb, you can set the third parameter to <tt>true</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.
 +
cue_definition.SetSound(sound_effect, Game1.audioEngine.GetCategoryIndex("Default"), false);
   −
// Adding the sound to the new cue.
+
// Adding the cue to the sound bank.
cue_definition.SetSound(sound_effect, audioEngine.GetCategoryIndex("Default"), false);
+
Game1.soundBank.AddCue(cue_definition);
 
  −
// Assigning the cue to the soundbank.
  −
soundBank.AddCue(cue_definition);
   
</syntaxhighlight>
 
</syntaxhighlight>
  
41

edits