【问题标题】:Restart CCDIrector cause weird error重新启动 CCDIrector 导致奇怪的错误
【发布时间】:2012-05-14 21:16:31
【问题描述】:

我正在尝试重新启动我的游戏 CCDirector。但我有错误。

所有这些都是我菜单中的代码 [我的菜单带有 XIB]:

- (void) retryGame:(NSNotification *)notif {
    [menu2Game.view removeFromSuperview];
    [[CCDirector sharedDirector] end];
    [[CCDirector sharedDirector] release];

    [self startGame:play];
}

它给了我和 EXC_BAD_ACCESS。就在我做两次的时候。第一个完美运行...

但如果删除

[self startGame:play];

我将返回菜单,然后单击播放按钮,我可以无限次执行它并且它有效!

我就这样退出了,我尝试了 20 次,它仍然有效。

- (void) quitGame:(NSNotification *)notif {
    [menu2Game.view removeFromSuperview];
    [[CCDirector sharedDirector] end];
    [[CCDirector sharedDirector] release];

    //Restart Animations
    [logo setFrame:CGRectMake(239, 119, 1, 1)];
    [play setFrame:CGRectMake(-233, play.frame.origin.y, play.frame.size.width, play.frame.size.height)];
    [options setFrame:CGRectMake(-233, options.frame.origin.y, options.frame.size.width, options.frame.size.height)];
    [extras setFrame:CGRectMake(-233, extras.frame.origin.y, extras.frame.size.width, extras.frame.size.height)];
    [GC setFrame:CGRectMake(0, 300, 1, 1)];

    [self viewDidLoad];
}

//在我的viewdidLoad中我只有动画

可能是什么问题?我尝试延迟 [perfomselector] 但它同样的问题......只要我返回菜单并单击播放,我就可以再次播放。无论速度如何,您都可以点击播放、暂停、退出、播放、暂停、退出等……游戏完美运行

谢谢

【问题讨论】:

    标签: iphone cocos2d-iphone


    【解决方案1】:

    CCDirector 是一个单例,你不应该向它发送发布消息!

    [[CCDirector sharedDirector] release];
    

    不这样做是完全可以的。值得一提的是,CCDirector startAnimation 和 stopAnimation 是更可行的暂时停止 Cocos2D 的方法。

    【讨论】:

    • 我遇到了同样的问题,我会发布更多信息...谢谢
    【解决方案2】:

    同样的问题

    - (void) retryGame:(NSNotification *)notif {
        [menu2Game.view removeFromSuperview];
        [[CCDirector sharedDirector] end];
        //[[CCDirector sharedDirector] release];
    
        [self startGame:play];
    }
    

    开始游戏

     - (IBAction)startGame:(id)sender {
    
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(quitGame:) name:@"quitGame" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(retryGame:) name:@"retryGame" object:nil];
    
        CCDirector *director = [CCDirector sharedDirector];
    
        // Init the View Controller
        menu2Game = [[Menu2Game alloc] initWithNibName:@"Menu2Game" bundle:nil];
        menu2Game.wantsFullScreenLayout = YES;
    
        //
        // Create the EAGLView manually
        //  1. Create a RGB565 format. Alternative: RGBA8
        //  2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
        //
        //
        EAGLView *glView = [EAGLView viewWithFrame:[self.view bounds]
                                       pixelFormat:kEAGLColorFormatRGB565   // kEAGLColorFormatRGBA8
                                       depthFormat:0                        // GL_DEPTH_COMPONENT16_OES
                            ];
    
        // attach the openglView to the director
        [director setOpenGLView:glView];
    
        // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
        //  if( ! [director enableRetinaDisplay:YES] )
        //      CCLOG(@"Retina Display Not supported");
    
    
        [director setAnimationInterval:1.0/60];
        [director setDisplayFPS:YES];
    
    
        // make the OpenGLView a child of the view controller
        [menu2Game setView:glView];
    
        // make the View Controller a child of the main window
        [self.view addSubview: menu2Game.view];
    
        // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
        // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
        // You can change anytime.
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    
        // Assusme PVR images have the alpha channel premultiplied
        [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
    
        // Run the intro Scene
        if ([director runningScene] == NULL) {
            [[CCDirector sharedDirector] runWithScene:[Game scene]];
        }else{
            [[CCDirector sharedDirector] replaceScene:[Game scene]];
        }
    }
    

    如果我评论 [self startGame:play];错误永远不会出现

    这里出现错误

    CCTextureAtlas.m [Cocos 2d]

    #if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
        glDrawElements(GL_TRIANGLE_STRIP, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(indices_[0])) );
    #else
        glDrawElements(GL_TRIANGLES, (GLsizei) n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6*sizeof(indices_[0])) );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2021-04-10
      相关资源
      最近更新 更多