在Popscene之后获取黑屏

get black screen after popScene

本文关键字:获取 之后 Popscene      更新时间:2023-10-16

我刚刚开始学习Cocos2DX,并使用基本的Helloworld项目。我在其中添加了第二秒和一个按钮以更改场景。但是,一旦执行了PopScene方法,屏幕就变成了黑色,并且没有弹出第一个场景。我不知道怎么了。这是我在helloworld.cpp中修改的代码:

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

第二秒中的代码:

#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:deallocing ccdireter 0x6906f0

验证popscene方法未运行两次,也许用户快速点击菜单项(或错误)。

将同时弹出当前和Helloworld场景,而导演没有场景可以显示。这也将解释董事交易。

您可以首先检查导演的runningScene是否与this相同(如:第二秒实例),然后致电POPSCENE。

我也有同样的问题,但是我解决了,我认为您可能已经将所有孩子从现场删除,检查您的Onexit或Destructor,以查看这两个功能中是否可用的任何版本/删除选项。

如果场景没有孩子,那将是黑色。