美文网首页
cocos2d源码分析(一):cocos2d_tests启动流程

cocos2d源码分析(一):cocos2d_tests启动流程

作者: 奔向火星005 | 来源:发表于2018-12-30 14:56 被阅读0次

为了研究cocos2d底层代码,挑选了官方ios平台的cocos2d_tests工程。首先对它的demo的整个流程和界面框架理一遍,以便后续查阅。

ios程序启动后,首先调用testsAppDelegate.mm文件中的AppController的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions代码,如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    cocos2d::Application *app = cocos2d::Application::getInstance();
    app->initGLContextAttrs();
    cocos2d::GLViewImpl::convertAttrs();

    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

    // Init the CCEAGLView
    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
                                         pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
                                         depthFormat: cocos2d::GLViewImpl::_depthFormat
                                  preserveBackbuffer: NO
                                          sharegroup: nil
                                       multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
                                     numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];

#if !defined(CC_TARGET_OS_TVOS)
    [eaglView setMultipleTouchEnabled:YES];
#endif

    // Use RootViewController manage CCEAGLView
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
#if !defined(CC_TARGET_OS_TVOS)
    viewController.wantsFullScreenLayout = YES;
#endif
    viewController.view = eaglView;

    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        // warning: addSubView doesn't work on iOS6
        [window addSubview: viewController.view];
    }
    else
    {
        // use this method on ios6
        [window setRootViewController:viewController];
    }
    
    [window makeKeyAndVisible];

#if !defined(CC_TARGET_OS_TVOS)
    [[UIApplication sharedApplication] setStatusBarHidden:true];
#endif
    
    // IMPORTANT: Setting the GLView should be done after creating the RootViewController
    cocos2d::GLView *glview = cocos2d::GLViewImpl::createWithEAGLView(eaglView);
    cocos2d::Director::getInstance()->setOpenGLView(glview);

    app->run();

    return YES;
}

大致流程图为:


app->run()后面的代码的流程图:


AppController相关类图为:


AppController

CCEAGLView相关类图为:


AppDelegate相关类图为:


AppDelegate

相关文章

网友评论

      本文标题:cocos2d源码分析(一):cocos2d_tests启动流程

      本文链接:https://www.haomeiwen.com/subject/zzjvlqtx.html