2014-01-22 31 views
0

我刚开始学习Cocos2dx,并使用基本的HelloWorld项目。我添加了一个SecondScene和一个按钮来改变场景。但是一旦执行popScene方法,屏幕变黑,并且不会弹出到第一个场景。我不知道什么是错的。 下面是我修改一点点在HelloWorld.cpp代码:popScene后得到黑屏

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) 
CCDirector::sharedDirector()->pushScene(SecondScence::scene()); 
#endif 

守则SecondScene:

#include "SecondScence.h" 
USING_NS_CC; 

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


bool SecondScence::init(){ 
CCLabelTTF* label = CCLabelTTF::create("hfiejfeiojfoej", "Arial", 30); 
label->setPosition(ccp(200,200)); 
this->addChild(label); 

CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png","CloseSelected.png",this,menu_selector(SecondScence::popScene)); 
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width-20, 20)); 

CCMenu *pMenu = CCMenu::create(pCloseItem,NULL); 
pMenu->setPosition(CCPointZero); 
this->addChild(pMenu,1); 

return true; 
} 

void SecondScence::popScene(CCObject* pSender){ 
    CCDirector::sharedDirector()->popScene(); 
} 

顺便说一句,我用cocos2dx 2.2和xcode5,在控制台打印一个消息:cocos2d的:cocos2d:释放CCDirector 0x6906f0

回答

0

确认popScene方法没有运行两次,也许是由用户快速点击菜单项(或一个错误)。

这将弹出当前和HelloWorld场景,让导演不显示场景。这也将解释导演释放。

您可以通过首先检查导演的runningScene是否与this(如在SecondScene实例中)相同,然后才调用popScene来阻止此操作。

0

我有同样的问题,但我却解决了, 我想你可能已经删除从场景中的所有儿童, 检查你的OnExit或析构函数,看看是否有释放/删除这两个函数可用选项。

如果现场没有小孩,那就是黑色。

+0

场景意味着你推入堆栈的场景。(pushScene()) –