我正在尝试在我的游戏中播放加载的 .wav 文件的 SoundEffectInstances,但我听不到任何声音。
我有一门课“ETSound”;每个物体都有一个声音。因此,一个 ETSound 对象可能会保持“菜单打开”的声音,而另一个可能会保持“坦克开火”的声音......等等。
无论如何,ETSound 构造函数如下所示:
public ETSound(SoundEffect se, float volume, float pitch, bool looped, int soundPriority) {
soundTemplate = se;
this.volume = volume;
this.pitch = pitch;
this.looped = looped;
if (soundPriority > 0) {
if (soundPriority > 64) soundPriority = 64;
instanceArray = new SoundEffectInstance[soundPriority];
nextInstanceIndex = 0;
for (int i = 0; i < soundPriority; ++i) {
SoundEffectInstance sei = soundTemplate.CreateInstance();
sei.Volume = volume;
sei.Pitch = pitch;
instanceArray[i] = sei;
}
}
}
这基本上设置了一些参数,并根据提供的 SoundEffect 创建了一组音效实例。
然后,我调用 ETSound 的 Play() 函数:
public void Play() {
if (instanceArray[nextInstanceIndex].State != SoundState.Stopped) instanceArray[nextInstanceIndex].Stop();
instanceArray[nextInstanceIndex].Play();
if (++nextInstanceIndex >= instanceArray.Length) nextInstanceIndex = 0;
}
然而,什么也没有发生。我什么也没听到。
谁能告诉我出了什么问题?谢谢。