2

在 iOS 上的 Cocos2dx 中,我无法重新启动同一场景。每当玩家死亡时,我都希望重新开始相同的场景。启动时会发生很多事情,所以如果可能的话,我宁愿不尝试手动重置所有游戏变量,清除缓存等。

在玩家死亡的部分,我执行以下操作

cocos2d::CCScene *pScene = GameScene::scene();
cocos2d::CCDirector::sharedDirector()->replaceScene(pScene);

但这会导致以下崩溃:

CCTextureCache::CCTextureCache()
{
    CCAssert(g_sharedTextureCache == NULL, "Attempted to allocate a second instance of a singleton.");
    m_pTextures = new CCDictionary();
}

Gamescene 继承自 CCLayer,其构造函数如下所示。

CCScene* GameScene::scene()
{
    CCScene *scene = CCScene::create();
    GameScene *layer = GameScene::create();
    scene->addChild(layer);     
    return scene;
}

应用程序在这条线上崩溃 GameScene *layer = GameScene::create(); 但我真的不能再进一步了。我在更换场景时做错了什么吗?

谢谢你的帮助

4

1 回答 1

0

Although you should implement proper checks in the scene() static function but I think that may not be causing the problem. If you can give all the code for this GameLayer class I might be able to point out your mistake because I have done what you are trying to do.

You are probably trying to do something illegal with the texture cache in your init function, that is my guess. But do post your code !

于 2013-08-28T20:24:41.520 回答