2011-02-08 79 views
1

我正在努力將Ben Gottlieb's Twitter-OAuth-iPhone代碼集成到我的cocos2d 0.99.5項目使用this tutorial。我有一些困難讓視圖控制器正確加載。我從來沒有將Cocos2d與標準的Cocoa Touch UI混合在一起,而且我的深度已經有點遠了。新的視圖控制器出現,然後消失在CCScene

我叫下面的代碼在我的應用程序的委託時,它的時間來連接到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; 
    } 
} 

當這個被調用時,Twitter的UIViewController被創建,它一旦動畫在屏幕上,然後,因爲它已完成動畫(即它到達屏幕的頂部),它消失。當前正在運行的CCScene會重新出現,但它不會響應觸摸。在模擬器上,不再顯示正在運行的場景,屏幕變黑。如果不清楚,viewController是最近在0.99.5中添加到cocos2d的RootViewController

在我看來,UIViewController正在創建,然後以某種方式繪製在運行場景下,但調試已經讓我無處可尋。我哪裏錯了?

回答

0

這裏尋求幫助後,在對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]; 
    } 

} 

總之,而不是推一個新場景暫停菜單,暫停我在遊戲中所有的行動,建立一個透明層覆蓋在屏幕上,然後顯示在其頂部的菜單。這似乎是在cocos2d中處理這個問題的傳統方法,至少從0.99.5開始(這正是遊戲當前的運行方式)。

0

您的視圖控制器應該是這樣的:

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

我應該澄清,viewController是該項目的RootViewController - 將其視圖添加到CCDirector的子視圖會創建一個無限循環,導致應用程序崩潰。這個問題現在已經編輯澄清。不過,我感謝幫助! – jonmorgan 2011-02-09 14:47:04

相關問題