我有一个应用程序。这个应用程序结合了UIKit和Cocos2D。 我有一个带有按钮的UIKit菜单,可以调用cocos2D游戏。它工作正常。
现在,我想删除cocos场景以推送UIKit菜单。 (游戏结束了,有必要进入菜单视图)
我试过
[[CCDirector sharedDirector] end];
[[CCDirector sharedDirector].openGLView removeFromSuperview];
它不起作用。我不知道该怎么做。
感谢您的帮助!
答案 0 :(得分:0)
在cocos2d 2.0及以上版本中尝试此操作:
呈现视图控制器:
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
//presentModalViewController
[app.navController presentModalViewController:leaderboardViewController animated:YES];
//dismissModalViewControllerAnimated:YES
[app.navController dismissModalViewControllerAnimated:YES];
添加子视图:
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController.view addSubview:mSegmentedControl];
答案 1 :(得分:0)
尝试做这样的事情。 当您在uiviewcontroller上推送cocos场景时,请在ViewDidLoad方法中添加此代码。
-(void)viewDidLoad{
[super viewDidLoad];
CCDirector *director = [CCDirector sharedDirector];
if([director isViewLoaded] == NO)
{
CCGLView *glView = [CCGLView viewWithFrame:[[[UIApplication sharedApplication] keyWindow] bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
director.view = glView;
[director setAnimationInterval:1.0f/60.0f];
[director enableRetinaDisplay:YES];
}
director.delegate = self;
[self addChildViewController:director];
[self.view addSubview:director.view];
[director didMoveToParentViewController:self];
if(director.runningScene)
{
[director replaceScene:[SceneFirst scene]];
}
else
{
[director runWithScene:[SceneFirst scene]];
}
}
这里的SceneFirst是你要推送的cocos场景。只需在你的UiViewController中添加CCDirectorDelegate作为委托。 并在ViewDidUnload方法中添加这行代码
[[CCDirector sharedDirector] setDelegate:nil];
要弹出回Uikit视图,请在任何CCmenu上点击
[[CCDirector sharedDirector] stopAnimation];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.navigationController popViewControllerAnimated:YES];
希望这个帮助!! :)
答案 2 :(得分:0)
This tutorial对我非常有用! 希望它有所帮助