music.cs

来自「Game Engine Desing Direct X and C#.rar」· CS 代码 · 共 55 行

CS
55
字号
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.AudioVideoPlayback;

namespace GameEngine
{
	/// <summary>
	/// Summary description for Music.
	/// </summary>
	public class Music : Microsoft.DirectX.AudioVideoPlayback.Audio
	{
		#region Attributes
		private bool  loop = false;
		#endregion

		#region Properties
		public bool  Loop { get { return loop; } set { loop = value; } }
		public float MusicVolume { set { base.Volume = (int)(-4000 * (1.0f - value)); } }
		#endregion

		/// <summary>
		/// Music constructor
		/// </summary>
		public Music( string filename ) : base(filename)
		{
			try
			{
				Ending += new System.EventHandler(this.ClipEnded);
			}
			catch (DirectXException d3de)
			{
				Console.AddLine("Unable to create music ");
				Console.AddLine(d3de.ErrorString);
			}
			catch ( Exception e )
			{
				Console.AddLine("Unable to create music ");
				Console.AddLine(e.Message);
			}
		}

		private void ClipEnded(object sender, System.EventArgs e)
		{
			// The clip has ended, stop and restart it
			if ( loop )
			{
				Stop();
				Play();
			}
		}

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?