2011-06-25 22 views
4

我有uiviewcontroller,用於在相機中使用某些效果。如何將UIViewcontroller整合到cocos2d場景中

上午在這個項目中使用了cocos2d lot。我只想如何將這個UIviewcontroller集成到cocos2d場景中。

使用uiviewwrapper爲UIView的整合

相同的UIView控制器的任何包裝物上呢?

在此先感謝。

回答

4

in MyViewController.h

add 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]]; 
+0

如果u使用導航控制器然後推it.otherwise如何調用該視圖 - 控制 – Srinivas

+0

[window addsubview:vc.View]; –

+0

在cocos2d場景中,我們不能添加uiwindow,那麼如何推這些.....我有一個疑問....是否cocos2d支持uiviewcontroller或不 – Srinivas