刚开始学Cocos2dx,就是用的HelloWorld的例子,自己加了SecondScene,做切换场景,HelloWorld里改为pushScene,在SecondScene里,加了个按钮执行popScene,但是一执行popScene,就黑屏了,没有实现返回上一场景的效果,请指点一下。
HelloWorld里修改的代码:
//ios平台
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// exit(0);
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
调试窗口打印了这样一条信息:Cocos2d: cocos2d: deallocing CCDirector 0x6906f0