C#游戏开发中快速的游戏循环
2015-06-05 07:59
543 查看
C#游戏开发中快速的游戏循环的实现。参考《精通C#游戏编程》一书。
---恢复内容结束---
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace GameLoop { [StructLayout(LayoutKind.Sequential)] public struct Message { public IntPtr hWnd; public Int32 msg; public IntPtr wParam; public IntPtr lParam; public uint time; public System.Drawing.Point p; } public class FastLoop { [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern bool PeekMessage( out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags); PreciseTimer _timer = new PreciseTimer(); public delegate void LoopCallback(); LoopCallback _callback; public FastLoop(LoopCallback callback) { _callback = callback; Application.Idle += new EventHandler(OnApplicationEnterIdle); } void OnApplicationEnterIdle(object sender, EventArgs e) { while (IsAppStillIdle()) { _callback(); } } private bool IsAppStillIdle() { Message msg; return !PeekMessage(out msg, IntPtr.Zero, 0, 0, 0); } } }
---恢复内容结束---
相关文章推荐
- C#游戏开发中精确的时间调配
- Some practices to write better C#/.NET code(译)
- 反射 C#
- c# C(m,n) 排列组合算法
- CLR.via.C#第三版 读书笔记
- C#中XmlSerializer实现序列化浅析
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- 系列文章——关于C#,你应该知道的2000件事情(002)
- c#自动更新+安装程序的制作
- C#进阶 WPF基础二 布局嵌套、菜单、工具栏、多窗口
- 【EmguCV】C#实现HOG与SVM的几个问题
- C#操作XML小结
- C# 字符串md5加密
- [C#] 汉字转拼音,支持多音字
- [C#] 汉字转拼音,支持多音字
- C#中调用SAPI实现语音合成的2种方法
- 偶尔在网上看到的,相对比较好的c#端订单号生成规则
- C#中调用SAPI实现语音识别的2种方法
- C#利用Renci.SshNet类库实现SFTP协议操作文件
- C# 透明背景Panel, 透明图像, PitureBox透明效果