【发布时间】:2011-07-20 14:13:30
【问题描述】:
我正在尝试在我的游戏中播放加载的 .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;
}
但是,什么也没有发生。我什么也没听到。
谁能告诉我出了什么问题?谢谢。
【问题讨论】:
-
我知道这是一个愚蠢的问题,但是您的扬声器已打开并且音量调高了吗?
-
是的,我现在正在听音乐(显然是为了测试而关闭的)。
-
什么是soundTemplate,它是如何创建实例的?
标签: c# xna audio soundeffectinstance