SoundEffect

Introduction

The SoundEffect class represents a sound effect that can be played at any time. If using Glue, a SoundEffect object can be created by adding a .WAV file to your project. If using code The SoundEffect class can be created from an XACT project, or through the content pipeline by processing a .WAV file.

The most common scenario is to add a WAV file to your Glue project. For more information on playing SoundEffects in Glue, see this page

Code Example

The following example assumes that you have “mySound.wav” added to your content project. If not using Glue, you will need to pass the .WAV file through the MonoGame content pipeline. Glue will automatically process .WAV files added to Screens, Entities, and Global Content Files.

// SoundEffects load through the content pipeline, so there is no extension
SoundEffect soundEffect = FlatRedBallServices.Load<SoundEffect>(@"Content\mySound");
// to play the sound, just call Play:
soundEffect.Play();