首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XNA C# SoundEffectInstance -无声音

XNA C# SoundEffectInstance -无声音
EN

Stack Overflow用户
提问于 2011-07-20 22:13:30
回答 1查看 644关注 0票数 0

我试图在我的游戏中播放加载的.wav文件的SoundEffectInstances,但我听不到任何声音。

我有一个“ETSound”类,每个对象都有一个声音。所以一个ETSound对象可能会保持“菜单打开”的声音,而另一个对象可能会保持“坦克射击”的声音。等。

无论如何,ETSound构造函数看起来像这样:

代码语言:javascript
复制
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()函数:

代码语言:javascript
复制
public void Play() { 
            if (instanceArray[nextInstanceIndex].State != SoundState.Stopped) instanceArray[nextInstanceIndex].Stop(); 
            instanceArray[nextInstanceIndex].Play(); 
            if (++nextInstanceIndex >= instanceArray.Length) nextInstanceIndex = 0;          
        } 

但是,什么也不会发生。我什么也没听到。

有人能告诉我出了什么问题吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-20 22:21:48

抱歉,各位...原来我用来测试的.wav文件已经损坏了...一个很难找到的bug,但我找到了。不管怎样,谢谢你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6763365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档