예제 #1
0
        public void PlaySound(SoundDefinition sound, Vector2 position)
        {
            var request = new SoundRequest();

            request.Sound    = sound;
            request.Position = position;
            soundRequests.Add(request);
        }
예제 #2
0
        public void PlaySound(SoundDefinition sound)
        {
            var request = new SoundRequest();

            request.Sound    = sound;
            request.Position = null;
            soundRequests.Add(request);
        }
예제 #3
0
        private void FireSound(SoundRequest request)
        {
            SoundEffectInstance instance = request.Sound.SoundEffect.CreateInstance();

            if (request.Position != null)
            {
                Vector2 relative = (Vector2)request.Position - ListenerPosition;
                instance.Pan = MathHelper.Clamp(relative.X / PanDivisor, -PanClamp, PanClamp);
            }
            instance.Pitch = (request.Sound.MaxPitchVariation / 2.0f) -
                             (float)random.NextDouble() * request.Sound.MaxPitchVariation;
            instance.Play();
            playingSounds.Add(instance);
        }