【问题标题】:EXC_BAD_ACCESS when ending scene in cocos2d在 cocos2d 中结束场景时的 EXC_BAD_ACCESS
【发布时间】:2012-03-03 02:59:01
【问题描述】:

我有一个普通的 iOS Cocos2d 游戏。我从 MainMenuViewController 开始,然后在按下“新游戏”按钮时推送我的 rootViewController,然后设置 cocos2d 场景和 HelloWorldLayer。我不确定这些是否相关。

问题是我什么时候想结束我的游戏。当玩家剩下 0 条生命并且检测到某个碰撞时,我希望场景结束,并且我想弹回我的主菜单。所以我在检测到碰撞后立即从我的update: (ccTime) dt 方法中调用以下方法:

-(void)endScene {
    [[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
    [[CCDirector sharedDirector] end];
    [_rootViewController.navigationController popViewControllerAnimated:YES];
}

问题是在结束场景时,我收到各种EXC_BAD_ACCESS 错误。我最常得到的一个是在 CCScheduler.m 中:

// delete all updates that are marked for deletion
// updates with priority < 0
DL_FOREACH_SAFE( updatesNeg, entry, tmp ) {
    if(entry->markedForDeletion )
    {
        [self removeUpdateFromHash:entry]; //THIS IS WHERE IS GET EXC_BAD_ACCESS
    }
}

Cocos2d 记录的唯一内容是

2012-03-02 13:36:20.849 Psycho Circles[25265:707] cocos2d: deallocing <CCScheduler: 0x3a3330>

任何帮助将不胜感激!

【问题讨论】:

    标签: ios cocos2d-iphone


    【解决方案1】:

    [[CCDirector sharedDirector] end];

    不是你用来结束场景的东西。

    看看这个例子如何切换场景:

    http://ganbarugames.com/2010/12/understanding-scenes-in-cocos2d-iphone/

    CCTransitionRotoZoom *transition = [CCTransitionRotoZoom transitionWithDuration:1.0 scene:[HelloWorld scene]];
    // Tell the director to run the transition
    [[CCDirector sharedDirector] replaceScene:transition];
    

    【讨论】:

    • 那个链接好像假设之前的画面也是Cocos2s的场景。我的问题是我只有一个场景,然后我想用 Cocos2d 完成,然后弹回我的第一个 ViewController,它不使用 Cocos2d,只是一个普通的 UIKit nib。所以我不明白为什么替换场景会有帮助。
    • 好的,我知道了——我只是停止选择器并在完成后弹出视图,然后当我回到游戏中时,我替换场景而不是重新启动。似乎有效。
    • 啊,好的。你是对的,这个例子是在场景之间切换的。我误解了你的问题,因为我认为菜单是另一个场景,就像我编写 iPhone 游戏时一样。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    相关资源
    最近更新 更多