Esempio n. 1
0
        /// <summary>
        /// Plays a sound effect.
        /// </summary>
        /// <param name="resourceId">The resource identifier.</param>
        /// <param name="channel">The specific audio channel to use.</param>
        public void PlaySoundEffect(int resourceId, int channel)
        {
            var args = new SoundEffectPlaybackEventArgs();

            args.ResourceId = resourceId;
            args.Channel    = channel;
            SoundEffectPlayback?.Invoke(this, args);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when a sound effect is played in the game.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Engine.Audio.SoundEffectPlaybackEventArgs"/> instance containing the event data.</param>
        private void OnGameSoundPlayback(object sender, SoundEffectPlaybackEventArgs e)
        {
            int handle = _soundResMan.GetSoundResourceHandle(e.ResourceId);

            if (handle == 0)
            {
                return;
            }

            if (e.Channel < 0 || e.Channel >= _channels.Length)
            {
                TraceSource.TraceEvent(TraceEventType.Warning, 0, $"Attempted to play back sample on invalid channel {e.Channel}.");
            }
            else
            {
                var channel = _channels[e.Channel];
                channel.PlaySound(handle);
            }
        }