mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
added SoundExtensions
This commit is contained in:
parent
3e3f0fc742
commit
e24c871ecd
2 changed files with 32 additions and 6 deletions
28
MLEM/Extensions/SoundExtensions.cs
Normal file
28
MLEM/Extensions/SoundExtensions.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using Microsoft.Xna.Framework.Audio;
|
||||
|
||||
namespace MLEM.Extensions {
|
||||
/// <summary>
|
||||
/// A set of extensions for dealing with <see cref="SoundEffect"/> and <see cref="SoundEffectInstance"/>
|
||||
/// </summary>
|
||||
public static class SoundExtensions {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SoundEffectInstance"/> from the given <see cref="SoundEffect"/>, allowing optional instance data to be supplied as part of the method call
|
||||
/// </summary>
|
||||
/// <param name="effect">The sound effect to create an instance from</param>
|
||||
/// <param name="volume">The value to set the returned instance's <see cref="SoundEffectInstance.Volume"/> to. Defaults to 1.</param>
|
||||
/// <param name="pitch">The value to set the returned instance's <see cref="SoundEffectInstance.Pitch"/> to. Defaults to 0.</param>
|
||||
/// <param name="pan">The value to set the returned instance's <see cref="SoundEffectInstance.Pan"/> to. Defaults to 0.</param>
|
||||
/// <param name="isLooped">The value to set the returned instance's <see cref="SoundEffectInstance.IsLooped"/> to. Defaults to false.</param>
|
||||
/// <returns></returns>
|
||||
public static SoundEffectInstance CreateInstance(this SoundEffect effect, float volume = 1, float pitch = 0, float pan = 0, bool isLooped = false) {
|
||||
var instance = effect.CreateInstance();
|
||||
instance.Volume = volume;
|
||||
instance.Pitch = pitch;
|
||||
instance.Pan = pan;
|
||||
instance.IsLooped = isLooped;
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.Xna.Framework.Audio;
|
||||
using MLEM.Extensions;
|
||||
|
||||
namespace MLEM.Misc {
|
||||
/// <summary>
|
||||
|
@ -49,13 +50,10 @@ namespace MLEM.Misc {
|
|||
/// <summary>
|
||||
/// Creates a new <see cref="SoundEffectInstance"/> with this sound effect info's data.
|
||||
/// </summary>
|
||||
/// <param name="isLooped">The value to set the returned instance's <see cref="SoundEffectInstance.IsLooped"/> to. Defaults to false.</param>
|
||||
/// <returns>A new sound effect instance, with this info's data applied</returns>
|
||||
public SoundEffectInstance CreateInstance() {
|
||||
var instance = this.Sound.CreateInstance();
|
||||
instance.Volume = this.Volume;
|
||||
instance.Pitch = this.Pitch;
|
||||
instance.Pan = this.Pan;
|
||||
return instance;
|
||||
public SoundEffectInstance CreateInstance(bool isLooped = false) {
|
||||
return this.Sound.CreateInstance(this.Volume, this.Pitch, this.Pan, isLooped);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue