Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:54:53+00:00 2026-05-28T16:54:53+00:00

I’ve been reading about the different ways of programming sound into a c# XNA

  • 0

I’ve been reading about the different ways of programming sound into a c# XNA game. I’ve decided on using a sound instance for the volume controls, but while playing a .wav, I’ve realised that the sound will only play again after it’s completed, whereas just using a Sound Effect .Play() (rather than an instance) will cause it to play multiple copies of themselves, should it be asked to. So my question is, in a scenario where holding down a button will cause a single sound effect to play multiple times at once (such as the repeating drone of a machine gun or the like), instead of waiting until the end of the sound file to loop; how would you use an instance? I assume that there is something I’m missing, or that an instance is not designed for this use. If so, what are the main differences between the basic options for a Sound Effect, and those of a Sound Effect Instance? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:54:54+00:00Added an answer on May 28, 2026 at 4:54 pm

    A SoundEffectInstance is one single instance of a sound playing; by definition, it cannot be played more than one at a time. Of course, you can have multiple instances of the same SoundEffect. In fact, this is basically what is happening when you call SoundEffect.Play(): you are creating an instance and playing it.

    With this in mind, there are several options on your plate. If you [presumably] want to prevent a billion sounds from fully playing when you hold down a button, you definitely should not be using SoundEffect.Play(), as like you’ve discovered, many many instances will be created (this is potentially very bad for performance and overall management anyway). For lesser-frequent sounds that may be an okay method.

    Having said that, in what way can the SoundEffectInstance be used? Basically it can be restarted from the beginning. Note that you can STILL have multiple SoundEffectInstances of course, one (or more) per game component. In this way one of your guns can restart and not mess with a different gun’s instance of the same sound. Or you can choose to only have one instance per sound effect for performance reasons.

    I’ve had problems with trying to restart it the “simple” way:

    instance.Stop();
    instance.Play();
    

    Historically this has not worked for me; if it does for you, disregard the following:

    What I had to do was set up my own “restart” flag per instance. So I wrapped the SoundEffectInstance class with my own like so:

    //class that represents one sound effect instance PLUS restart flag
    public class Sound
    {
        SoundEffectInstance instance;
        bool restart;
    
        public Sound(SoundEffectInstance i)
        {
            instance = i;
            restart = false;
        }
    
        public bool PlayingOrRestarting()
        {
            return State == SoundState.Playing || restart;
        }
    
        public void Update()
        {
            if (restart)
            {
                instance.Play();
                restart = false;
            }
        }
    
        public void Play()
        {
            instance.Play();
        }
    
        public void Restart()
        {
            instance.Stop();
            restart = true;
        }
    
        public void Stop()
        {
            instance.Stop();
            restart = false;
        }
    
        public SoundState State
        {
            get { return instance.State; }
        }
    
        public float Volume
        {
            set { instance.Volume = value; }
            get { return instance.Volume; }
        }
    
        public bool IsLooped
        {
            set { instance.IsLooped = value; }
            get { return instance.IsLooped; }
        }
    }
    

    With this method you have to call Update() every frame for every Sound, so keep a collection of them somewhere or make them otherwise accessible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.