gpt4 book ai didi

iphone - 如何在cocos2d场景中集成UIViewcontroller

转载 作者:行者123 更新时间:2023-12-03 19:14:19 26 4
gpt4 key购买 nike

我有 uiviewcontroller 在相机中使用一些效果。

我在这个项目中使用了cocos2d。我想知道如何将这个 UIviewcontroller 集成到 cocos2d 场景中。

使用 uiviewwrapper 进行 UIview 集成

与 UIview Controller 相同,有包装器吗?

提前致谢。

最佳答案

在 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

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

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

关于iphone - 如何在cocos2d场景中集成UIViewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6478127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com