int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// create the application instance
AppDelegate 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 director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
glview = GLViewImpl::create("Cpp Empty Test");
director->setOpenGLView(glview);
}
director->setOpenGLView(glview);
// turn on display FPS
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don‘t call this
director->setAnimationInterval(1.0 / 60);
// create a scene. it‘s an autorelease object
auto scene = HelloWorld::scene();
// run
director->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-iphone
virtual bool init();
// there‘s no ‘id‘ in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* scene();
// a selector callback
void menuCloseCallback(Ref* sender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
};
Scene* HelloWorld::scene()
{
// ‘scene‘ is an autorelease object
auto scene = Scene::create();
// ‘layer‘ is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
原文:http://www.cnblogs.com/dydx/p/4295941.html