我刚开始学习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
场景意味着你推入堆栈的场景。(pushScene()) –