我试图在我的游戏中播放加载的.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;
} 但是,什么也不会发生。我什么也没听到。
有人能告诉我出了什么问题吗?谢谢。
发布于 2011-07-20 22:21:48
抱歉,各位...原来我用来测试的.wav文件已经损坏了...一个很难找到的bug,但我找到了。不管怎样,谢谢你。
https://stackoverflow.com/questions/6763365
复制相似问题