我正在使用一个UIViewController来实现一些相机效果。
在这个项目中,我经常使用Cocos2d。我想知道如何将这个UIViewController集成到Cocos2d场景中。
我正在使用UIViewWrapper来进行UIView的集成。
同样的,是否有任何包装器可以用于UIViewController呢?
提前感谢您的帮助。
我正在使用一个UIViewController来实现一些相机效果。
在这个项目中,我经常使用Cocos2d。我想知道如何将这个UIViewController集成到Cocos2d场景中。
我正在使用UIViewWrapper来进行UIView的集成。
同样的,是否有任何包装器可以用于UIViewController呢?
提前感谢您的帮助。
在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
如果您不想创建新的视图控制器,那么可以简单地使用以下方法:
[[CCDirector sharedDirector]replaceScene:[NewLayer scene]];