0
\$\begingroup\$

I have recently added some Sound Effects to my game, but the problem that I am dealing with now, is that they have for a half of second delay, or more sometimes.

Also, if I press repeatedly on that button, the sound effect does not play each time that I press on the button, and when I finish pressing, it plays at least once (I think from the previous presses).

How can I fix this problem? Here is my Play function, if it will help with something ...

public void Play(SFX effect)
    {
        if(!Muted)
        {
            switch(effect)
            {
                case SFX.ButtonTap:
                    tapSfx_Instance.Play();
                    break;
                case SFX.Hit:
                    hitSfx_Instance.Play();
                    break;
                case SFX.Die:
                    dieSfx_Instance.Play();
                    break;
            }
        }
    }

Thanks.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It may just be that the sound is not done playing, and you are continually asking it to resume. This could potentially create a delay, depending on your logic.

You may want to add a few lines to see if solves your problem:

public void Play(SFX effect)
{
    if(!Muted)
    {       
        switch(effect)
        {
            case SFX.ButtonTap:
                if (tapSfx_Instance.State != SoundState.Playing) 
                    tapSfx_Instance.Play();
                break;
            case SFX.Hit:
                if (hitSfx_Instance.State != SoundState.Playing) 
                    hitSfx_Instance.Play();
                break;
            case SFX.Die:
                if (dieSfx_Instance.State != SoundState.Playing) 
                    dieSfx_Instance.Play();
                break;
        }
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Now is better, but still I do not get the result that I wanted. The sound effect stars in delay of 0.4, 0.5 seconds from the moment that I press on the button ... \$\endgroup\$
    – Edvin
    Aug 14, 2015 at 9:54
  • \$\begingroup\$ Make sure there is no gap in the actual audio file. You may need to edit the audio to remove any padding that may be present. \$\endgroup\$
    – jgallant
    Aug 14, 2015 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .