开发者

Difference between SoundEffect and SoundEffectInstance classes

开发者 https://www.devze.com 2023-02-21 05:12 出处:网络
Like in question, i don\'t get what is the difference between using those classes. What are advantages and limitations of each class. I readmany tutorials, and still can\'t decide what should i do.

Like in question, i don't get what is the difference between using those classes. What are advantages and limitations of each class. I read many tutorials, and still can't decide what should i do.

To make things more clear, i got AudioModule, AudioEmitterComponent and AudioListenerComponent. (Our game's eninge is based on component. When you create and object which is source of some sounds (monster or sth), i add emitter component.. and i got problems then. I can't figure out how to do it best. First i wanted Audio Module to got List, the same for listeners (and also lists for wave and soundbanks). Now i got problem, not in coding itself (at the moment) but with the concept what, where, when, why. Any ideas are valu开发者_高级运维able :)


Think of SoundEffect as being the sound file. You can load these using content manager.

And SoundEffectInstance as a program playing the sound file.

SoundEffect has a Play method. This is just for convenience. What this does internally is create a SoundEffectInstance, play it, and then clean up when it finishes. (Known as "fire and forget".)

When using SoundEffectInstance (that you create with SoundEffect.CreateInstance) you need to manage all of that yourself - the advantage is that you can manipulate the properties of the sound (volume, etc) while the sound is playing. You can also loop the sound, stop or pause part way through, etc.

When you finish with your SoundEffectInstance, don't forget to Dispose() of it!

Another thing you can do with SoundEffectInstance (which is entirely optional) is apply a 3D effect to it. This gives you an easy way to "place" the sound in 3D space. You apply the 3D effect using SoundEffectInstance.Apply3D (giving it a listener and an emitter that provide information about the camera and the sound source). The exact details of this are best left to the "Applying a 3D Positional Effect to a Sound" article on MSDN.

0

精彩评论

暂无评论...
验证码 换一张
取 消