【发布时间】: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
【问题讨论】: