简体   繁体   English

出现新的视图控制器,然后消失在CCScene后面

[英]New view controller appears and then disappears behind CCScene

I'm working on integrating Ben Gottlieb's Twitter-OAuth-iPhone code into my cocos2d 0.99.5 project using this tutorial . 我正在使用本教程Ben Gottlieb的Twitter-OAuth-iPhone代码集成到我的cocos2d 0.99.5项目中。 I'm having some difficulties getting the view controller to properly load. 我在使视图控制器正确加载方面遇到一些困难。 I've never mixed cocos2d with standard Cocoa Touch UI things before and I'm a bit out of my depth. 我以前从未将cocos2d与标准的Cocoa Touch UI东西混合在一起,但我的深度还不够。

I call the following code in my app delegate when it's time to connect to Twitter: 当我要连接到Twitter时,在我的应用程序委托中调用以下代码:

-(void) twitterAccountLogin
{
    UIViewController *controller = nil;
    if (!_engine) {
        _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
        _engine.consumerKey = kOAuthConsumerKey;
        _engine.consumerSecret = kOAuthConsumerSecret;

        controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
    }

    if (controller) {
        [[CCDirector sharedDirector] stopAnimation];
        [viewController presentModalViewController:controller animated:YES];
        [controller release];
        return;
    }
} 

When this is called, the Twitter UIViewController is created, it animates onscreen, and then, as soon as it has finished animating (ie it reaches the top of the screen), it disappears. 调用此方法时,将创建Twitter UIViewController并在屏幕上进行动画处理,然后,一旦完成动画处理(即到达屏幕顶部),它就会消失。 The currently running CCScene reappears, but it doesn't respond to touches. 重新运行当前正在运行的CCScene ,但是它对触摸没有响应。 On the simulator, instead of the running scene reappearing, the screen turns black. 在模拟器上,屏幕不再变黑,而不是重新显示运行的场景。 In case it is unclear, viewController is the RootViewController recently added to cocos2d in 0.99.5. 如果不清楚, viewControllerviewController中最近添加到cocos2d的RootViewController

It seems to me that the UIViewController is being created and then somehow is drawn under the running scene, but debugging has gotten me nowhere. 在我看来,正在创建UIViewController ,然后以某种方式在正在运行的场景下进行绘制,但是调试无处可寻。 Where have I gone wrong? 我哪里出问题了?

your view controller should be something like this: 您的视图控制器应该是这样的:

[[[CCDirector sharedDirector]openGLView] addSubview: viewController.view]; 
[viewController presentModalViewController: controller animated:YES];

After searching for help here and on the cocos2d forums, here's what I have ended up doing. 在这里和cocos2d论坛上寻求帮助之后,这就是我最终要做的事情。

-(void)pauseMenuButtonPressed
{    
    if(!paused)
    {
        paused = TRUE;

        [[CCDirector sharedDirector] pause];

        CGSize s = [[CCDirector sharedDirector] winSize];
        pauseLayer = [CCColorLayer layerWithColor: ccc4(150, 150, 150, 125) width: s.width height: s.height];
        pauseLayer.position = CGPointZero;
        [self addChild: pauseLayer z:8];

        CCMenuItem *pauseMenuItemResume =[CCMenuItemImage itemFromNormalImage:@"menuItemResumeSmall.png"
                                                            selectedImage: @"menuItemResumeSmallSelected.png"
                                                                   target:self
                                                                 selector:@selector(pauseMenuResumeSelected)];


        CCMenuItem *pauseMenuItemMainMenu =[CCMenuItemImage itemFromNormalImage:@"menuItemMainMenuSmall.png"
                                                              selectedImage: @"menuItemMainMenuSmallSelected.png"
                                                                     target:self
                                                                   selector:@selector(pauseMenuExitToMainMenuSelected)];

        // Create the pause menu and add the menu items to it
        pauseMenu = [CCMenu menuWithItems:pauseMenuItemResume, pauseMenuItemMainMenu, nil];

        // Arrange the menu items vertically
        [pauseMenu alignItemsVertically];

        // add the menu to the scene
        [self addChild:pauseMenu z:10];

        [hudButtons setIsTouchEnabled:NO];
    }

}

In short, rather than pushing a new scene for a pause menu, I pause all action in the game, create a transparent layer to overlay the screen, and then display the menu on top of that. 简而言之,我没有暂停游戏菜单中的所有操作,而是暂停了游戏中的所有动作,创建了一个透明层来覆盖屏幕,然后在其上方显示菜单。 This appears to be the conventional means of handling this problem in cocos2d, at least as of 0.99.5 (which is what the game is currently running in). 至少从0.99.5起,这似乎是在cocos2d中处理此问题的常规方法(这是游戏当前正在运行的状态)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM