Programming 2D Games 读书笔记(第二章)
生活随笔
收集整理的這篇文章主要介紹了
Programming 2D Games 读书笔记(第二章)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
本意還是想了解DirectX的,由于網上拿不到書的pdf文檔,幸好有作者的源代碼示例,想完整的看一下,基本的游戲需要的點.
下面直接以代碼為例,僅用于幫助自身理解
http://www.programming2dgames.com/chapter2.htm
示例一:Hello World
創建了一個標準的Win32消息循環程序示例
示例二:Character Input
介紹了鍵盤輸入消息WM_CHAR
case WM_CHAR: // a character was entered by the keyboardswitch (wParam) // the character is in wParam{case 0x08: // backspacecase 0x09: // tabcase 0x0A: // linefeedcase 0x0D: // carriage returncase 0x1B: // escapeMessageBeep((UINT) -1); // beep but do not displayreturn 0;default: // displayable characterch = (TCHAR) wParam; // get the characterInvalidateRect(hwnd, NULL, TRUE); // force WM_PAINTreturn 0;}示例三:Keys Down
介紹了鍵盤消息
case WM_KEYDOWN: // key downvkKeys[wParam] = true;switch(wParam){case VK_SHIFT: // shift keynVirtKey = GetKeyState(VK_LSHIFT); // get state of left shiftif (nVirtKey & SHIFTED) // if left shiftvkKeys[VK_LSHIFT] = true;nVirtKey = GetKeyState(VK_RSHIFT); // get state of right shiftif (nVirtKey & SHIFTED) // if right shiftvkKeys[VK_RSHIFT] = true;break;case VK_CONTROL: // control keynVirtKey = GetKeyState(VK_LCONTROL);if (nVirtKey & SHIFTED) // if left controlvkKeys[VK_LCONTROL] = true;nVirtKey = GetKeyState(VK_RCONTROL);if (nVirtKey & SHIFTED) // if right controlvkKeys[VK_RCONTROL] = true;break;}InvalidateRect(hwnd, NULL, TRUE); // force WM_PAINTreturn 0;break;示例四:Prevent Multiple
使用Mutex實現單實例
bool AnotherInstance() {HANDLE ourMutex;// Attempt to create a mutex using our unique stringourMutex = CreateMutex(NULL, true, "Use_a_different_string_here_for_each_program_48161-XYZZY");if (GetLastError() == ERROR_ALREADY_EXISTS)return true; // another instance was foundreturn false; // we are the only instance }總結
以上是生活随笔為你收集整理的Programming 2D Games 读书笔记(第二章)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自创小插件让emacs支持工程项目
- 下一篇: 自己Ubuntu里面的一些小脚本