コード例 #1
0
        public static void PlayQueuedSoundEffects()
        {
            // Remove all sound effects that have finished.
            currentSfx.RemoveAll(x => x.Instance.State == SoundState.Stopped);

            SoundEffectInstance sound;
            SoundEffectInstanceWrapper newSound;

            foreach(SoundEffectQueueItem sfx in sfxQueue)
            {
                try
                {
                    if(currentSfx.Count >= 28)
                        CancelEarliestSoundEffect();

                    sound = sfx.soundEffect.CreateInstance();
                    sound.Volume = masterVolume * sfx.soundEffectVolume * sfxVolume;
                    sound.Pitch = sfx.soundEffectPitch;

                    newSound = new SoundEffectInstanceWrapper(sound, sfx.cancellable);
                    currentSfx.Add(newSound);

                    newSound.Instance.Play();
                }
                catch(InstancePlayLimitException e)
                {
                    Console.WriteLine("InstancePlayLimitException at " + currentSfx.Count + " instances.");
                }
            }

            sfxQueue.Clear();
        }
コード例 #2
0
        public static void CancelEarliestSoundEffect()
        {
            SoundEffectInstanceWrapper toCancel = currentSfx.FindAll(x => x.Cancellable)[0];

            toCancel.Instance.Stop();
            currentSfx.Remove(toCancel);
        }
コード例 #3
0
        public static void PlayQueuedSoundEffects()
        {
            // Remove all sound effects that have finished.
            currentSfx.RemoveAll(x => x.Instance.State == SoundState.Stopped);

            SoundEffectInstance        sound;
            SoundEffectInstanceWrapper newSound;

            foreach (SoundEffectQueueItem sfx in sfxQueue)
            {
                try
                {
                    if (currentSfx.Count >= 28)
                    {
                        CancelEarliestSoundEffect();
                    }

                    sound        = sfx.soundEffect.CreateInstance();
                    sound.Volume = masterVolume * sfx.soundEffectVolume * sfxVolume;
                    sound.Pitch  = sfx.soundEffectPitch;

                    newSound = new SoundEffectInstanceWrapper(sound, sfx.cancellable);
                    currentSfx.Add(newSound);

                    newSound.Instance.Play();
                }
                catch (InstancePlayLimitException e)
                {
                    Console.WriteLine("InstancePlayLimitException at " + currentSfx.Count + " instances.");
                }
            }

            sfxQueue.Clear();
        }
コード例 #4
0
        public static SoundEffectInstance PlaySong(SoundEffect thisSong, bool looping = true, float volumeMod = 1f)
        {
            SoundEffectInstance instance = thisSong.CreateInstance();

            instance.IsLooped = looping;
            instance.Volume   = masterVolume * musicVolume * volumeMod;
            SoundEffectInstanceWrapper song = new SoundEffectInstanceWrapper(instance, false, true);

            currentSfx.Add(song);
            instance.Play();

            return(instance);
        }