1、游戏从main文件开始
image.pngimage.png
Application::getInstance()->run() 启动游戏
2、AppDelegate.h 游戏生命周期
image.png四个纯虚构函数
(1)applicationDidFinishLaunching 正在运行
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
// 初始化 director
// auto C++ 11 自动类型识别,类似java中的object,typeid(director).name() 能输出类型
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("GameDemo1", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create("GameDemo1");
#endif
director->setOpenGLView(glview);
}
// 设置是否显示fps帧数
director->setDisplayStats(true);
// 1秒60fps
director->setAnimationInterval(1.0f / 60);
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
auto frameSize = glview->getFrameSize();
// if the frame's height is larger than the height of medium size.
if (frameSize.height > mediumResolutionSize.height)
{
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is larger than the height of small size.
else if (frameSize.height > smallResolutionSize.height)
{
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is smaller than the height of medium size.
else
{
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
}
register_all_packages();
// 创建一个场景
// create a scene. it's an autorelease object
auto scene = HelloWorld::createScene();
// 运行场景
director->runWithScene(scene);
return true;
}
image.png
applicationDidEnterBackground 进入后台
applicationWillEnterForeground 从后台切换至前台
网友评论