官網:
http://www.cocos2d-x.org/
裏面有一個cocos2d-win32.vc2012.sln的文件 用visual studio打開(根據自己的版本號)
因爲安卓 iphone什麼的太麻煩 就先從win32開始吧 (反正可以跨平臺沒事)
這個工程, 就是hello world(設置成啓動項就可以直接編譯運行)
然後test是各種功能的效果可以運行 有個概念。
接下來我們來看hello world的代碼
首先從main函數開始:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// create the application instance
AppDelegate app;
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
eglView->setViewName("HelloCpp");
eglView->setFrameSize(2048, 1536);
// The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
// So we need to invoke 'setFrameZoomFactor'(only valid on desktop(win32, mac, linux)) to make the window smaller.
eglView->setFrameZoomFactor(0.4f);
return CCApplication::sharedApplication()->run();
}
這個是全局的入口 。主要設置窗臺大小和幀數什麼的。
重點是
AppDelegate app;
這句纔是遊戲邏輯的入口