如何在cocos2d场景中集成UIViewcontroller

4

我正在使用一个UIViewController来实现一些相机效果。

在这个项目中,我经常使用Cocos2d。我想知道如何将这个UIViewController集成到Cocos2d场景中。

我正在使用UIViewWrapper来进行UIView的集成。

同样的,是否有任何包装器可以用于UIViewController呢?

提前感谢您的帮助。

1个回答

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

如果您不想创建新的视图控制器,那么可以简单地使用以下方法:

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

如何调用这个视图控制器。 - Srinivas
如果您使用导航控制器,则推送它。否则,使用 [window addsubview:vc.View]。 - Vijay-Apple-Dev.blogspot.com
在cocos2d的场景中,我们无法添加UIWindow。那么如何推送这些内容呢?我有一个问题:cocos2d是否支持UIViewController? - Srinivas
我在一个文档中读到,cocos2d不支持带有xib的视图控制器......因为cocos2d不支持Interface Builder.....我认为在cocos2d中有任何包装器可用于UIViewController...... - Srinivas
看一下项目的rootviewcontroller。它没有nib文件,只是将视图附加到glview上。 - Vijay-Apple-Dev.blogspot.com

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接