【问题标题】:Cocos 2d application structureCocos 2d 应用结构
【发布时间】:2011-07-13 11:47:45
【问题描述】:

我是cocos2d 的新手,想了解一些关于cocos2d 应用程序结构的知识。 这是默认模板中appdidfinishlaunching函数中的代码。

- (void) applicationDidFinishLaunching:(UIApplication*)application
{
    // Init the window
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Try to use CADisplayLink director
    // if it fails (SDK < 3.1) use the default director
    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];


    CCDirector *director = [CCDirector sharedDirector];

    // Init the View Controller
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;

    //
    // Create the EAGLView manually
    //  1. Create a RGB565 format. Alternative: RGBA8
    //  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
    //
    //
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                   depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                        ];

    // attach the openglView to the director
    [director setOpenGLView:glView];

//  // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
//  if( ! [director enableRetinaDisplay:YES] )
//      CCLOG(@"Retina Display Not supported");

    //
    // VERY IMPORTANT:
    // If the rotation is going to be controlled by a UIViewController
    // then the device orientation should be "Portrait".
    //
    // IMPORTANT:
    // By default, this template only supports Landscape orientations.
    // Edit the RootViewController.m file to edit the supported orientations.
    //
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
    [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

    [director setAnimationInterval:1.0/60];
    [director setDisplayFPS:YES];


    // make the OpenGLView a child of the view controller
    [viewController setView:glView];

    // make the View Controller a child of the main window
    [window addSubview: viewController.view];

    [window makeKeyAndVisible];

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change anytime.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];


    // Removes the startup flicker
    [self removeStartupFlicker];

    // Run the intro Scene
    [[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];     
}

我的问题是,当我们向 CCDirector 添加一些孩子时,当 CCDirector 导演从未添加到 window.view 时,如何在屏幕上显示这个东西 我们有以下几行代码

// 使 OpenGLView 成为视图控制器的子项 [viewController setView:glView];

这会将 RootViewController 的视图设置为 glView 并且在此之前我们正在设置

[导演setOpenGLView:glView]; 表示director的openglView设置为glView。

假设可以添加导演,我们是否不必将导演添加到视图控制器,这样无论我们向导演添加什么内容,它都会在屏幕上可见。

我的问题是当我们从未在 RootViewController 上添加 CCDirector 时,场景应该如何在 iphone 屏幕上可见。

【问题讨论】:

    标签: iphone cocos2d-iphone


    【解决方案1】:

    CCDirector 将 glView 设置为 RootViewController 的视图。所有下一个绘图都是使用opengl制作的。在 glView.所以像CCLayer、CCNode、CCSprite等cocos2d的类,跟UIView或者UIViewController什么都没有

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-21
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      相关资源
      最近更新 更多