我有一个通常的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>
任何帮助将不胜感激!
答案 0 :(得分:0)
[[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];