首页 > Computer > XNA > How To: Play a Sound
2009
02-22

How To: Play a Sound

Demonstrates how to play a sound.

To play a sound without using XACT, you will use the SoundEffect or SoundEffectInstance classes. Using these classes is simpler than using XACT and the classes required by XACT.

Because XACT is not available on Zune, the SoundEffect and SoundEffectInstance will be the only option for Zune games.

SoundEffect and SoundEffectInstance are also available for Xbox and Windows XNA games.

Simple Sound Playing

Declare SoundEffect.

C#
// Audio objects SoundEffect soundEffect; string soundName = "kaboom"; 

Play the sound.

C#
ContentManager contentManager = new ContentManager(this.Services, @"Content\"); soundEffect = contentManager.Load<soundeffect>(soundName); soundEffect.Play();

最后编辑:
作者:wy182000
这个作者貌似有点懒,什么都没有留下。

留下一个回复