int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow){UNREFERENCED_PARAMETER(hPrevInstance);UNREFERENCED_PARAMETER(lpCmdLine);// create the application instanceAppDelegate app;return Application::getInstance()->run();}
Application::Application(): _instance(nullptr), _accelTable(nullptr){_instance = GetModuleHandle(nullptr);_animationInterval.QuadPart = 0;CC_ASSERT(! sm_pSharedApplication);sm_pSharedApplication = this;}
Application* Application::getInstance(){CC_ASSERT(sm_pSharedApplication);return sm_pSharedApplication;}
bool AppDelegate::applicationDidFinishLaunching() {// initialize directorauto director = Director::getInstance();auto glview = director->getOpenGLView();if(!glview) {glview = GLViewImpl::create("Cpp Empty Test");director->setOpenGLView(glview);}director->setOpenGLView(glview);// turn on display FPSdirector->setDisplayStats(true);// set FPS. the default value is 1.0/60 if you don‘t call thisdirector->setAnimationInterval(1.0 / 60);// create a scene. it‘s an autorelease objectauto scene = HelloWorld::scene();// rundirector->runWithScene(scene);return true;}
class HelloWorld : public cocos2d::Layer{public:// Here‘s a difference. Method ‘init‘ in cocos2d-x returns bool, instead of returning ‘id‘ in cocos2d-iphonevirtual bool init();// there‘s no ‘id‘ in cpp, so we recommend returning the class instance pointerstatic cocos2d::Scene* scene();// a selector callbackvoid menuCloseCallback(Ref* sender);// implement the "static node()" method manuallyCREATE_FUNC(HelloWorld);};
Scene* HelloWorld::scene(){// ‘scene‘ is an autorelease objectauto scene = Scene::create();// ‘layer‘ is an autorelease objectHelloWorld *layer = HelloWorld::create();// add layer as a child to scenescene->addChild(layer);// return the scenereturn scene;}
原文:http://www.cnblogs.com/dydx/p/4295941.html