1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
|
#include "main.h" #include "AppDelegate.h" #include "CCEGLView.h"USING_NS_CC; LRESULT myWndProcHook(UINT message, WPARAM wParam, LPARAM lParam, BOOL* pProcessed); // uncomment below line, open debug console // #define USE_WIN32_CONSOLE
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); #ifdef USE_WIN32_CONSOLE AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); #endif // create the application instance AppDelegate app; CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setFrameSize(480, 320); //eglView->setFrameSize(960, 640); //eglView->setFrameSize(2048, 1536); //eglView->setFrameZoomFactor(0.4f); eglView->setWndProc(myWndProcHook); //增加這一句
int ret = CCApplication::sharedApplication()->run(); #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif return ret; } LRESULT myWndProcHook(UINT message, WPARAM wParam, LPARAM lParam, BOOL* pProcessed) { switch (message) { case WM_KEYDOWN: case WM_KEYUP: { //以FrameSize == DesignResolutionSize時的座標設定 CCPoint pt = CCPointZero; switch (wParam) { case 'A': //向左 { pt = ccp(25, 255); } break; case 'D': //向右 { pt = ccp(95, 256); } break; case 'W': //向上 { pt = ccp(63, 214); } break; case 'S': //向下 { pt = ccp(62, 290); } break; case 'J': //攻擊 { pt = ccp(367, 277); } break; case 'K': //跳躍 { pt = ccp(445, 247); } break; default: return 0; } if (GetKeyState('D') & 0x8000) { if (GetKeyState('W') & 0x8000) //右上方 { pt = ccp(91, 227); } else if (GetKeyState('S') & 0x8000) //右下角 { pt = ccp(91, 284); } } else if (GetKeyState('A') & 0x8000) { if (GetKeyState('W') & 0x8000) //左上方 { pt = ccp(36, 227); } else if (GetKeyState('S') & 0x8000) //左下角 { pt = ccp(36, 284); } } CCEGLView* eglView = CCEGLView::sharedOpenGLView(); CCSize originalDesignResolutionSize = CCSizeMake(480, 320); //原始的設計解析度大小 ResolutionPolicy eResolutionPolicy = kResolutionFixedWidth; //解析度策略 CCSize obDesignResolutionSize = eglView->getDesignResolutionSize(); int offsetWidth = obDesignResolutionSize.width - originalDesignResolutionSize.width; int offsetheight = obDesignResolutionSize.height - originalDesignResolutionSize.height; CCSize obScreenSize = eglView->getFrameSize(); int offsetWidth2 = obScreenSize.width - originalDesignResolutionSize.width; int offsetheight2 = obScreenSize.height - originalDesignResolutionSize.height; switch (eResolutionPolicy) { case kResolutionExactFit: { //... } break; case kResolutionNoBorder: { //... } break; case kResolutionShowAll: { pt.x += offsetWidth2 / 2; pt.y += offsetheight2 / 2; } break; case kResolutionFixedHeight: { //... } break; case kResolutionFixedWidth: { pt.y += offsetheight; } break; } pt.x *= eglView->getScaleX(); pt.y *= eglView->getScaleY(); int id = wParam; if (message == WM_KEYDOWN) { eglView->handleTouchesBegin(1, &id, &pt.x, &pt.y); } else { eglView->handleTouchesEnd(1, &id, &pt.x, &pt.y); } *pProcessed = TRUE; } break; } return 0; } |