[英]When changing view controllers, new controller appears, but disappears almost immediately
[英]New view controller appears and then disappears behind CCScene
我正在使用本教程將Ben Gottlieb的Twitter-OAuth-iPhone代碼集成到我的cocos2d 0.99.5項目中。 我在使視圖控制器正確加載方面遇到一些困難。 我以前從未將cocos2d與標准的Cocoa Touch UI東西混合在一起,但我的深度還不夠。
當我要連接到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
是viewController
中最近添加到cocos2d的RootViewController
。
在我看來,正在創建UIViewController
,然后以某種方式在正在運行的場景下進行繪制,但是調試無處可尋。 我哪里出問題了?
您的視圖控制器應該是這樣的:
[[[CCDirector sharedDirector]openGLView] addSubview: viewController.view];
[viewController presentModalViewController: controller animated:YES];
在這里和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];
}
}
簡而言之,我沒有暫停游戲菜單中的所有操作,而是暫停了游戲中的所有動作,創建了一個透明層來覆蓋屏幕,然后在其上方顯示菜單。 至少從0.99.5起,這似乎是在cocos2d中處理此問題的常規方法(這是游戲當前正在運行的狀態)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.