环境:win7+vs2010
版本:2.2.2
在win32平台的环境中,是从传统的main函数开始执行的。打开cocos2d-x引擎根目录\projects\你的项目\proj.win32文件夹中的main.cpp
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
#ifdef USE_WIN32_CONSOLE
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
#endif
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// create the application instance
AppDelegate app;
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
eglView->setViewName("TestDemo");
eglView->setFrameSize(720, 480);
int ret = CCApplication::sharedApplication()->run();
#ifdef USE_WIN32_CONSOLE
FreeConsole();
#endif
return ret;
}
在这个主函数的执行中,先初始化控制台,再在栈中创建cocos2d-x的AppDelegate的实例。
AppDelegate app;然后创建OpenGL的窗口
CCEGLView* eglView = CCEGLView::sharedOpenGLView(); eglView->setViewName("TestDemo"); eglView->setFrameSize(720, 480);
最后调用run函数,开始运行cocos2d-x游戏。
int ret = CCApplication::sharedApplication()->run();