如何在cocos2d场景中集成UIViewcontroller

时间:2011-06-25 13:47:01

标签: iphone uiviewcontroller cocos2d-iphone

我正在使用uiviewcontroller在相机中使用某些效果。

我正在为这个项目使用cocos2d。我想要如何在cocos2d场景中集成这个UIviewcontroller。

使用uiviewwrapper进行UIview集成

与UIview控制器相同,任何包装器都在那里吗?

提前感谢。

1 个答案:

答案 0 :(得分:4)

在MyViewController.h中

添加MyViewController * mviewController;

MyViewcontroller.m中的

#import "MyViewcontroller.h"


//before push mviewController 

    if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
        [CCDirector setDirectorType:kCCDirectorTypeDefault];


    CCDirector *director = [CCDirector sharedDirector];

    mviewController = [[MyViewcontroller alloc] initWithNibName:nil bundle:nil];
    mviewController.wantsFullScreenLayout = YES;



    EAGLView *glView = [EAGLView viewWithFrame:[[UIScreen mainScreen] 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");

#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
    [mviewController setView:glView];

    [[CCDirector sharedDirector]replaceScene:[NewLayer scene]];


//here push that viewController

如果你不想创建新的viewcontroller那么你可以简单地使用

[[CCDirector sharedDirector]replaceScene:[NewLayer scene]];