/// <summary> /// 初始导演类 /// </summary> /// <returns>是否初始化成功</returns> public bool Init() { try { //预设参数 PresentParameters pp = new PresentParameters(); pp.Windowed = true; pp.SwapEffect = SwapEffect.Discard; //创建设备 d3dDevice = new Microsoft.DirectX.Direct3D.Device( 0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pp ); //input设备 kbDevice = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Keyboard); kbDevice.SetCooperativeLevel(this, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background); kbDevice.Acquire(); //if (instance != null) return false; instance = this; //设置每帧时间间隔 PerFrameTick = 1000.0f / 60; return true; } catch (DirectXException e) { ErrorReport.New(e); return false; } }
static void Main(string[] args) { using (Director director = new Director()) { if (!director.Init()) { ErrorReport.New("初始化DirectX失败!"); return; } director.Show(); AnimationLoader.aaa(); TimerUtils.Init(); while (director.Created) { director.Play(); Application.DoEvents(); } } }
/// <summary> /// 退出程序 /// </summary> public void Exit() { currentScene.Dispose(); d3dDevice.Dispose(); instance = null; this.Dispose(); this.Close(); }