【问题标题】:XNA C# SoundEffectInstance - no soundXNA C# SoundEffectInstance - 没有声音
【发布时间】: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


【解决方案1】:

对不起,大家...原来我用来测试的 .wav 文件已损坏...一个很难找到的错误,但我明白了。还是谢谢。

【讨论】:

    猜你喜欢
    • 2012-03-28
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2017-10-19
    • 2021-04-22
    • 2016-05-06
    • 1970-01-01
    相关资源
    最近更新 更多