【问题标题】:Removing Cocos2D from a ViewController从 ViewController 中移除 Cocos2D
【发布时间】:2013-01-13 07:35:53
【问题描述】:

我在 iOS 应用中有一个普通的故事板。它包含带有按钮的 ViewController "A"。当该按钮被点击时,它会加载一个 Cocos2D 视图 - 为此,我只需从创建新 Cocos2D 项目时获得的默认 AppDelegate 复制代码:

window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                               pixelFormat:kEAGLColorFormatRGB565   
                               depthFormat:0    
                        preserveBackbuffer:NO
                                sharegroup:nil
                             multiSampling:NO
                           numberOfSamples:0];

[glView setMultipleTouchEnabled:YES];

director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

director_.wantsFullScreenLayout = YES;

[director_ setDisplayStats:YES];


[director_ setAnimationInterval:1.0/60];

[director_ setView:glView];

[director_ setDelegate:self];

[director_ setProjection:kCCDirectorProjection2D];

if( ! [director_ enableRetinaDisplay:YES] )
    CCLOG(@"Retina Display Not supported");

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"


[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];


[director_ pushScene: [HelloWorldLayer scene]];


navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;

[window_ setRootViewController:navController_];


[window_ makeKeyAndVisible];

这一切都很好,加载“HelloWorldLayer”时它就像一个魅力。 但是,我似乎无法删除此“HelloWorldLayer”并使应用程序重新使用情节提要。 目前我的“HelloWorldLayer”中有一个函数,它执行以下操作:

[[CCDirector sharedDirector].openGLView removeFromSuperview];
[[CCDirector sharedDirector] removeFromParentViewController];
[self removeFromParentAndCleanup:TRUE];

这在从项目中删除 Cocos2D 时效果很好,但是在完成上述操作后,我无法点击 ViewController“A”中的任何内容:按钮不响应触摸 - 就好像应用程序已冻结一样。

我们将不胜感激!

PS:这是一个有问题的文件的链接:http://www.mediafire.com/?ipnlpinl5i0lw4a

【问题讨论】:

标签: ios cocoa uiviewcontroller cocos2d-iphone


【解决方案1】:

好的,我想通了:在第一行代码中分配的 window_ 仍然覆盖 ViewController A。一旦 HelloWorldLayer 视觉上消失,我必须从 ViewController A 调用 [window_ release] 才能将其移除路。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-27
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    相关资源
    最近更新 更多