【问题标题】:get black screen after popScenepopScene 后黑屏
【发布时间】:2014-01-22 14:07:37
【问题描述】:

我刚开始学习 Cocos2dx,并使用基本的 HelloWorld 项目。我在其中添加了一个 SecondScene 和一个按钮来更改场景。但是一旦执行了 popScene 方法,屏幕就变黑了,并且没有弹出到第一个场景。我不知道出了什么问题。 这是我在 HelloWorld.cpp 中稍微修改的代码:

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

【问题讨论】:

    标签: c++ cocos2d-x


    【解决方案1】:

    验证 popScene 方法没有运行两次,可能是用户快速点击菜单项(或错误)。

    这将同时弹出当前场景和 HelloWorld 场景,让导演没有场景可显示。它还可以解释主任解除分配的原因。

    您可以通过首先检查导演的runningScene 是否与this 相同(如:SecondScene 实例)来防止这种情况,然后才调用popScene。

    【讨论】:

      【解决方案2】:

      我也有同样的问题,但我解决了, 我想你可能已经把所有的孩子都从现场移走了, 检查你的 onExit 或析构函数,看看这两个函数中是否有可用的释放/删除选项。

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

      【讨论】:

      • 场景表示你压入堆栈的场景。(pushScene())
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 2020-07-11
      • 2021-08-07
      相关资源
      最近更新 更多