using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Media; namespace MyGame { class SoundEffectExample { private SoundEffectInstance mySound; public void LoadContent(ContentManager content) { mySound = content.Load("mySound").CreateInstance(); } public void Update() { if (condition) { mySound.Play(); } } } }
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Media; namespace MyGame { class SoundEffectExample { private SoundEffect mySound; public void LoadContent(ContentManager content) { mySound = content.LoadIn this example, we define a SoundEffect object named mySound. It is loaded by using the ContentManager class from an external file. When the condition is true, we first create a SoundEffectInstance object from our SoundEffect object, then we call the Play() method on that instance to play the sound. The package library for this method is the Microsoft.Xna.Framework package.("mySound"); } public void Update() { if (condition) { SoundEffectInstance instance = mySound.CreateInstance(); instance.Play(); } } } }
public Play ( ) : void | ||
return | void |