Line 236: |
Line 236: |
| | | |
| ===Adding and playing custom sounds=== | | ===Adding and playing custom sounds=== |
| + | |
| + | (This section is still a work in progress.) |
| + | |
| + | Game audio is split up into components: |
| + | *The SoundEffect is the object that stores the sound audio itself. |
| + | *The Cue is the object that stores the sound name, the SoundEffect, and any other settings or properties the sound has. |
| + | *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 sounds to the soundbank, you can define a new <tt>CueDefinition</tt> and add a name: |
| + | <syntaxhighlight lang="c#"> |
| + | CueDefinition cue_definition = new CueDefinition(); |
| + | cue_definition.name = "myNewSound"; |
| + | </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: |
| <syntaxhighlight lang="c#"> | | <syntaxhighlight lang="c#"> |
− | // Create a new Cue Definition. | + | // If this sound is played multiple times in quick succession, |
− | CueDefinition cue_definition = new CueDefinition();
| + | // only one sound instance will play at a time. |
− | cue_definition.name = "Test"; | + | cue_definition.instanceLimit = 1; |
| + | cue_definition.limitBehavior = CueDefinition.LimitBehavior.ReplaceOldest; |
| + | </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>. |
| + | <syntaxhighlight lang="c#"> |
| + | // Make a SoundEffect object, and fetch the sound file to then add. |
| + | SoundEffect sound_effect; |
| + | using (var stream = new System.IO.FileStream("mySound.wav", System.IO.FileMode.Open)) |
| + | { |
| + | sound_effect = SoundEffect.FromStream(stream); |
| + | } |
| + | </syntaxhighlight> |
| + | |
| + | Lastly, add the <tt>SoundEffect</tt> to the cue, and assign the cue to the soundbank to be stored. |
| + | |
| + | 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#"> |
| + | |
| + | // Adding the sound to the new cue. |
| + | cue_definition.SetSound(sound_effect, audioEngine.GetCategoryIndex("Default"), false); |
| + | |
| + | // Assigning the cue to the soundbank. |
| + | soundBank.AddCue(cue_definition); |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | TODO
| + | You should now be able to play your sound using any of the sound commands! |
| + | <syntaxhighlight lang="c#"> |
| + | Game1.playSound("myNewSound"); |
| + | </syntaxhighlight> |
| | | |
| ==Track list== | | ==Track list== |